iOS安全-录屏、截屏判断

5,316 阅读1分钟

##截屏:iOS7+ 截屏事件通知:

UIApplicationUserDidTakeScreenshotNotification

注册接收截屏动作的通知事件:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(takePicture:) name:UIApplicationUserDidTakeScreenshotNotification object:nil]

截屏动作selector:

- (void)takePicture:(NSNotification *)notification {
    //Do sth...
}

##录屏:iOS11+ 在需要获取是否录屏的地方进入时,可以根据

NSLog(@"AppStart: Screen is captured: %@", [UIScreen mainScreen].isCaptured ? @"YES" : @"NO");

判断是否在录屏状态 而当录屏状态改变时,UIKit会发送录屏通知:

UIScreenCapturedDidChangeNotification

其中,notification的object为一个UIScreen *,其中的isCaptured属性,可以用来判断当前是否处于录屏状态。

注册接收录屏状态改变的通知事件:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(captureChanged:) name:UIScreenCapturedDidChangeNotification object:nil];

接收通知selector:

- (void)captureChanged:(NSNotification *)notification {
    UIScreen *screen = notification.object;
    NSLog(@"receive notification: Screen is captured: %@", screen.isCaptured ? @"YES" : @"NO");
    if(screen.isCaptured) {
        //Do sth...
    }
}