How to understand if device screen is being recorded in IOS 11

半城伤御伤魂 提交于 2020-01-04 14:11:26

问题


I have an application that it has copyrighted content. I don't want users to record it. If they start recording screen I want my app to catch this. What is the function to catch if the screen is being recorded?

I don't want to prevent, I want to understand and catch it.

Note: Some answers indicate solutions including AirPlay and Mirroring. What I want is to only catch screen recording either started before or during app. I want to allow users to use AirPlay and Mirroring.


回答1:


You can check if the screen is being recorded with this

UIScreen.main.isCaptured



回答2:


isCaptured will be true if the screen is being recorded, mirrored or sent over AirPlay.

I added a check to see if mirroring is the case; if not, I show an alert. Solved my issue for the time being. This is not a perfect solution and doesn't solve all the problems, but just one extra step towards it

if (@available(iOS 11.0, *)) {
  [[NSNotificationCenter defaultCenter] addObserver:self
                selector:@selector(handleScreenCaptureChange)
   name:UIScreenCapturedDidChangeNotification object:nil];
}

-(void)handleScreenCaptureChange
{
    UIScreen *aScreen;
    BOOL isMainScreenMirrored = NO;
    NSArray *screens = [UIScreen screens];
    for (aScreen in screens)
    {
        if ([aScreen respondsToSelector:@selector(mirroredScreen)]
            && [aScreen mirroredScreen] == [UIScreen mainScreen])
        {
            // The main screen is being mirrored.
            isMainScreenMirrored = YES;
        }
    }

    if (@available(iOS 11.0, *)) {
        BOOL isCaptured = [[UIScreen mainScreen] isCaptured];
        if (isCaptured && !isMainScreenMirrored) {

            //Display Alert : "Please turn off screen recording and play again."

        }
    }
}



回答3:


You can also detect if user has taken screenshot by listening to UIApplicationUserDidTakeScreenshotNotification.

You can use that in below way-

let main = OperationQueue.main
NotificationCenter.default.addObserver(forName: NSNotification.Name.UIApplicationUserDidTakeScreenshot, 
    object: nil, 
    queue: mainQueue, 
    using: { notification in
        // Warn user
})

And

UIScreen.main.isCaptured

This can also be used to detect recording. I haven't used this but mostly you will have to do KVO for this.




回答4:


Check the screen is being recorded (for Objective C)

Put the below code on your app delegate and did finish launching and did become active.

BOOL isCaptured = [[UIScreen mainScreen]isCaptured];




回答5:


Use UIScreen.main.isCaptured to get current status. Than, you need to listen to new notification UIScreenCapturedDidChangeNotification. When recording status will change, you need to do some action (for example stop playback ..etc.). Remember this is iOS11+ only.

Code fragments:

if (@available(iOS 11.0, *)) {
  [[NSNotificationCenter defaultCenter] addObserver:self
                    selector:@selector(capturedChange)
   name:UIScreenCapturedDidChangeNotification object:nil];
}


- (void)capturedChange {
    if (@available(iOS 11.0, *)) {
    NSLog(@"Recording Status: %s", [UIScreen mainScreen].isCaptured ? "true" : "false");
        //do something
    } 
}


来源:https://stackoverflow.com/questions/46217459/how-to-understand-if-device-screen-is-being-recorded-in-ios-11

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!