Search code examples
iosscreenshotbackground-process

Detect screenshots taken ON ANY APP within my iOS app


Is it possible to detect when the user takes a screenshot in any app while my app is in the background ? And how would I do that ?

If not, can I background check regularly for screenshots (not pictures from the camera) in the photo library ? Like every minute or hour ?


Solution

  • One way to get your app to detect Screenshots is:

    1. Register with the Photo Library's PHPhotoLibraryChangeObserver

    2. When your app receives a notification that a photo has been added, check its PHAssetMediaSubtype

    3. If the Subtype is PHAssetMediaSubtypePhotoScreenshot, you know a new Screenshot has been taken.

    The PHPhotoLibraryChangeObserver protocol notifies you of changes that occur in the Photos library, regardless of whether those changes are made by your app, by a user in the Photos app, or by another app that uses the Photos framework.

    https://developer.apple.com/reference/photos/phphotolibrarychangeobserver