ios 监听截屏和录屏方法

截屏监听

-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(screenshots) name:UIApplicationUserDidTakeScreenshotNotification  object:nil];
}
-(void)screenshots
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"[安全提醒]内含个人重要信息,请不要截图,录制或分享给他人以保障您的账户安全。" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
    [alert1 show];

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

监听录屏

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];

//监测当前设备是否处于录屏状态
    UIScreen * sc = [UIScreen mainScreen];
    if (@available(iOS 11.0, *)) {
        if (sc.isCaptured) {
            NSLog(@"正在录制~~~~~~~~~%d",sc.isCaptured);
            [self screenshots];
        }
    } else {
        // Fallback on earlier versions
    }
    if (@available(iOS 11.0, *)) {
//检测到当前设备录屏状态发生变化
        [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(screenshots) name:UIScreenCapturedDidChangeNotification  object:nil];
    } else {
        // Fallback on earlier versions
    }
}

-(void) screenshots
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"[安全提醒]内含个人重要信息,请不要截图,录制或分享给他人以保障您的账户。" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
    [alert1 show];

-(void)dealloc
{
    if (@available(iOS 11.0, *)) {
        [[NSNotificationCenter defaultCenter] removeObserver:self name:UIScreenCapturedDidChangeNotification object:nil];
    } else {
        // Fallback on earlier versions
    }
}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容