Skip to content

iOS Detect Screenshot

Platform Language License

userDidTakeScreenshotNotification

It will be triggered when user take screenshot's.

func detectScreenShot(action: @escaping () -> ()) {
    //Creating in main Queue
    let mainQueue = OperationQueue.main
    NotificationCenter.default.addObserver(forName: UIApplication.userDidTakeScreenshotNotification, object: nil, queue: mainQueue) { notification in
        // Executes after ScreenShot
        action()
    }
}

Just call like

detectScreenShot {
    print("ScreenShot taken")
}

When ever we add observer we have to remove. Don't forget to remove.

NotificationCenter.default.removeObserver(UIApplication.userDidTakeScreenshotNotification)

We can't restrict user to take screenshot. If you found best way let me know.

Note: Try in iPhone device for best result.

Let's grow together 🌱

Cheers 🍻