iMessage Extension Screenshot Detection

I have an iMessage extension and I am trying to detect screenshots when the extension is opened. I have tried every observer I have found online and for some reason it is not registering screenshots.

I have tried:
UIScreen.main.addObserver(self, forKeyPath: "captured", options: .new, context: nil)
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey: Any]?, context: UnsafeMutableRawPointer?) {
if (keyPath == "captured") {
let isCaptured = UIScreen.main.isCaptured
print(isCaptured)
screenshot()
//screenshot() sends a message alerting the message was screens hotted. However, the print statement didn't even run.
}
}

I have also tried:
let mainQueue = OperationQueue.main
NotificationCenter.default.addObserver(forName: UIApplication.userDidTakeScreenshotNotification, object: nil, queue: mainQueue) { notification in
// executes after screenshot
print("Screenshotted")
self.screenshot()
}

Any ideas on how to detect this in an iMessage Extension?

Any ideas on how to detect this in an iMessage Extension?

You might have more luck your question somewhere dedicated to iOS-specifics, perhaps the App Frameworks > iMessage Apps and Stickers topic area on DevForums?

Share and Enjoy

Quinn “The Eskimo!” @ DTS @ Apple

Ah, I see you already created a DevForums thread for your question. Cool beans.

Share and Enjoy

Quinn “The Eskimo!” @ DTS @ Apple