0 Replies
      Latest reply on Mar 14, 2019 10:08 PM by levikline
      levikline Level 1 Level 1 (0 points)

        I have searched everywhere on how to detect screenshots, but none of the methods I have found have proved to work within my iMessage extension. I have tried one method:

         

        UIScreen.main.addObserver(self, forKeyPath: "captured", options: .new, context: nil)
        

         

        with the other method being:

         

        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()
        }
        

         

        and nothing has worked. Does anybody know how I can possibly check if a user has taken a screenshot with my iMessage extension open?