截屏监听 iOS

做安全的有部分页面不想让截屏或者录屏,但是iOS实现不了不让截屏或者录屏,但是提供的截屏或者录屏的监听方法,当用户截屏或录屏时系统会发送相关通知。

截屏通知名:UIApplicationUserDidTakeScreenshot

具体方法:

-(void)viewDidLoad {
    [super viewDidLoad];
    //增加监听->监听截图事件
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleSceenShot) name:UIApplicationUserDidTakeScreenshotNotification object:nil];
    
}

//当用户截屏了 怎么办 目前来说 只能进行提示。或者告诉服务器进行统计
-(void)handleSceenShot {
    UIAlertController * alertVc =[UIAlertController alertControllerWithTitle:@"信息提示" message:@"请不要截屏或录屏!" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction * knowAction =[UIAlertAction actionWithTitle:@"知道了" style:UIAlertActionStyleDefault handler:nil];
    [alertVc addAction:knowAction];
    [self presentViewController:alertVc animated:YES completion:nil];
}

//记得要要销毁通知哦

-(void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationUserDidTakeScreenshotNotification object:nil];
}

 

 

 

你可能感兴趣的:(APP开发)