Search code examples
iosobjective-cuiscreen

iOS Screen recording detection


I tried to detect if screen capture is on for the application for iOS 11, to detect this the UIScreen.mainScreen.isCaptured property is used to check if it is recorded.

It works fine for the first launch, when the app is terminated and launched again, then the API returns NO though the screen capture is on.

Code:

//In viewWillAppear block

__block ViewController *weakSelf = self;
  [NSTimer scheduledTimerWithTimeInterval:2.0 repeats:YES block:^(NSTimer * _Nonnull timer) {
    [weakSelf screenCaptureDetection];
  }];

- (void) screenCaptureDetection {
  if (@available(iOS 11.0, *)) {
    for (UIScreen *screen in [UIScreen screens]) {
      if([screen performSelector:@selector(isCaptured)]){
      //Detected YES
    }
  }
}

Use case scenario:

  1. Launch the app
  2. Start screen recorder using the apple screen recording option
  3. The screen recorder is detected
  4. Terminate the app
  5. Repeat the step 1 and 2
  6. The screen recording is not detected, the API UIScreen.mainScreen.isCaptured returns NO

Please suggest


Solution

  • You should check for recording repeatedly.

    I used this code and it worked for me. check it out:

    https://gist.github.com/abhimuralidharan/8db55dff9023028867b719f251372bd7#file-screenrecordingdetector-m