美文网首页藤原とうふ店(自家用)
ios 禁止截屏、录屏 监听事件做弹框提示

ios 禁止截屏、录屏 监听事件做弹框提示

作者: 木子李55 | 来源:发表于2020-02-25 00:15 被阅读0次
梦乡.jpeg

ios不能做到禁止截屏和录屏,只能使用通知监听到截屏或录屏事件,来做一些处理,比如停止播放视频等。

如果想要监听整个app运行期间的所有页面,则把监听方法写到appdelegate中;如果只是监听指定页面,则把监听方法写到指定页面。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    // 截屏
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(takeScreenTest) name:UIApplicationUserDidTakeScreenshotNotification object:nil];
    
    // iOS11后中新增了录屏功能
    if (@available(iOS 11.0, *)) {
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(captureScreenTest) name:UIScreenCapturedDidChangeNotification object:nil];
    }
    
    return YES;
}

-(void)takeScreenTest{
    [self alertTakeScreenWithStr:@"您在截屏,请注意保护个人隐私"];
}
-(void)captureScreenTest{
    if (@available(iOS 11.0, *)) {
        // 开始录屏时有弹框提示,结束录屏时就不弹框了。
        if (![UIScreen mainScreen].isCaptured) {
            return;
        }
        [self alertTakeScreenWithStr:@"您在录屏,请注意保护个人隐私"];
    }
}
-(void)alertTakeScreenWithStr:(NSString *)str{
    NSLog(@"监听到截屏或录屏");
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:str preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        NSLog(@"点击了确定");
    }];
    [alertController addAction:okAction];
    // 如果是页面,用self;如果在appdelegate中,用self.window.rootViewController
    [self.window.rootViewController presentViewController:alertController animated:YES completion:nil];
}

做了个demo,传到了github仓库,需要的可以下载看看:https://github.com/zhuzi55/BanTakeScreenDemo.git

相关文章

  • ios 禁止截屏、录屏 监听事件做弹框提示

    ios不能做到禁止截屏和录屏,只能使用通知监听到截屏或录屏事件,来做一些处理,比如停止播放视频等。 如果想要监听整...

  • Android安全:禁止APP录屏和截屏

    一、前言: Android有些APP会为了安全,禁止录屏和截屏,例如:金融、银行相关的。禁止录屏和截屏并不难,只需...

  • Android安全:禁止APP录屏和截屏

    一、前言: Android有些APP会为了安全,禁止录屏和截屏,例如:金融、银行相关的。禁止录屏和截屏并不难,只需...

  • Android安全:禁止APP录屏和截屏

    一、前言: Android有些APP会为了安全,禁止录屏和截屏,例如:金融、银行相关的。禁止录屏和截屏并不难,只需...

  • iOS 录屏和截屏监听

    iOS 录屏和截屏监听--记录一下笔记 源起 最近公司应用安全检查,在用户登录页面要防止截屏和录屏导致用户名密码等...

  • Android安全性:禁止APP内截屏和录屏

    现在很多Android的APP会为了安全,禁止截屏录屏,例如:银行、金融相关的。 禁止录屏和截屏其实并不难,只需要...

  • Android安全:禁止APP录屏和截屏

    一、前言:Android有些APP会为了安全,禁止录屏和截屏,例如:金融、银行相关的。禁止录屏和截屏并不难,只需要...

  • 禁止APP录屏和截屏

    Android有些APP会为了安全,禁止录屏和截屏,例如:金融、银行相关的。禁止录屏和截屏并不难,只需要在 Act...

  • 禁止APP录屏和截屏

    Android有些APP会为了安全,禁止录屏和截屏,例如:金融、银行相关的。禁止录屏和截屏并不难,只需要在 Act...

  • iOS 如何实现禁止截屏和录屏

    禁止截屏最简单的实现方法 偶然机会发现,当输入框是密码形式时,截屏和录屏都不能获取到输入框的内容,所以想到,如果把...

网友评论

    本文标题:ios 禁止截屏、录屏 监听事件做弹框提示

    本文链接:https://www.haomeiwen.com/subject/zytnqhtx.html