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?