How to check iOS11 Screen Recording is On or Off?

ios swift ios11

2190 观看

4回复

31 作者的声誉

For detecting iOS11 screen recording feature On or Off I used isCaptured and UIScreenCapturedDidChange Notification.

When first time I Launch the App and On iOS11 built-in screen recording feature then it notifies the selector method with value True, but when I kill (terminate) my running App and Launch app again do the same procedure again then my selector method is not getting called.

Here is my code:

I add an Observer in ViewWillAppear() method:

NotificationCenter.default.addObserver(self, selector: #selector(handleNotification), name: NSNotification.Name.UIScreenCapturedDidChange, object: nil)

The selector method is as follows:

@objc
func handleNotification(notification:Notification){

    let isCaptured = UIScreen.main.isCaptured

    print("isCaptured value = \(isCaptured)")
}

In this case, I need to kill the app, clear the cache and again launch the app for getting screen recording event.

Please suggest what I can do here to detect recording event to protect my content from recording.

作者: UmeshKumath 的来源 发布者: 2017 年 9 月 15 日

回应 4


2

1757 作者的声誉

I guess you can alway check this variable regardless of the notification

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.
    let isCaptured = UIScreen.main.isCaptured
    return true
}
作者: yasirmturk 发布者: 2017 年 9 月 15 日

4

1531 作者的声誉

Swift 4

Add Observer

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

Receive changes

override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey: Any]?, context: UnsafeMutableRawPointer?) {
    if (keyPath == "captured") {
        let isCaptured = UIScreen.main.isCaptured

        print(isCaptured)
    }
}
作者: dimo hamdy 发布者: 2018 年 3 月 4 日

0

1 作者的声誉

this is the way to detect if a screenshot has been taken

func detectScreenShot(action: @escaping () -> ()) {
    let mainQueue = OperationQueue.main
    NotificationCenter.default.addObserver(forName: UIApplication.userDidTakeScreenshotNotification, object: nil, queue: mainQueue) { notification in
        // executes after screenshot
        action()
    }
}
作者: Roberto Font 发布者: 2019 年 1 月 27 日

0

586 作者的声誉

The feature is available on and above iOS11. Better keep it inside didFinishLaunchingWithOptions

Objective-C syntax

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: 
 (NSDictionary *)launchOptions
{
if (@available(iOS 11.0, *)) {
    BOOL isCaptured = [[UIScreen mainScreen] isCaptured];
    if(isCaptured){
       // Do the action for hiding the screen recording
                  } 
   } else{
        // Fallback on earlier versions
         }
 return YES;
}
作者: Ankit Aman 发布者: 2019 年 1 月 30 日
32x32