0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

スクショ・画面録画されたことを通知する方法

Posted at

スクリーンショットや画面録画がされたことを通知するには,そのViewControllerの中で

override func viewWillAppear(_ animated: Bool) {

        NotificationCenter.default.addObserver(self, 
        selector: #selector(didTakeScreenshot), name:                                UIApplication.userDidTakeScreenshotNotification, object: nil)
        
        NotificationCenter.default.addObserver(
            self,
            selector: #selector(didCapturedScreen),
            name: UIScreen.capturedDidChangeNotification,
            object: nil
        )
        
    }

ViewDidLoad()でも構いません。
didTakeScreenshotdidCapturedScreen自分で決める関数であるので、例えば以下のようにします。

@objc func didTakeScreenshot() {
    print("スクリーンショット")
 }

必要に応じて通知を削除します。

override func viewWillDisappear(_ animated: Bool) {
        super.viewWillAppear(animated)
        NotificationCenter.default.removeObserver(self,name: UIApplication.userDidTakeScreenshotNotification, object: nil)
        NotificationCenter.default.removeObserver(self, name: UIScreen.capturedDidChangeNotification, object: nil)
    }
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?