防截屏、防录屏

2,555 阅读2分钟

一、弹出安全提示

安卓可以阻断系统截屏、录屏,从而防止信息泄露。
苹果无法阻断,可在捕捉到截屏、录屏事件后弹出一个安全提示。(弹出视图覆盖整个页面也可达到防录屏效果,但是用户体验一般)

加两个通知:UIApplicationUserDidTakeScreenshotNotification,UIScreenCapturedDidChangeNotification(可以把代码封装到一个单例里面,避免多次注册通知导致多次弹窗的问题)

//(防)截屏通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(takeScreenshot) name:UIApplicationUserDidTakeScreenshotNotification object:nil];

//(防)录屏通知
if (@available(iOS 11.0, *)) {
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(takeScreenRecording) name:UIScreenCapturedDidChangeNotification object:nil];
}

// MARK: - (防)截屏通知
- (void)takeScreenshot{
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"风险提示" message:@"使用中请不要截屏或分享给他人,以保障账户安全。" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {}];
    [alert addAction:okAction];
    [self presentViewController:alert animated:YES completion:nil];
}

// MARK: - (防)录屏通知
- (void)takeScreenRecording{
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"风险提示" message:@"使用中请不要录屏或分享给他人,以保障账户安全。" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {}];
    [alert addAction:okAction];
    [self presentViewController:alert animated:YES completion:nil];
}

.

二、拓展:

1、给用户显示警示内容(就是上述的方案)

2、在页面上加水印(水印加在刘海那个位置,平时是被刘海挡住的看不到,截图后是可以看到的)

3、暴力删除相册截图(检测到截屏后直接删除相册照片)

4、UITextField:当我们将一个 UITextField 的 isSecureTextEntry 设置为 true 的时候,会隐去输入的文案用 圆点 替代。并且在进行录屏或者截屏的时候都会被系统隐去。(我们可以利用这一特性)

5、ScreenShieldKit(这个SDK是收费的)

.

三、问题:如果是从App外就开始录屏了,是检测不到的

处理:

// 监测当前设备是否处于录屏状态
UIScreen *sc = [UIScreen mainScreen];
BOOL isCaptureds = NO;
if (@available(iOS 11.0, *)) {
    if (sc.isCaptured) {
        showErrorMessage(@"检测到正在录屏,请勿将敏感信息分享给他人");
        isCaptureds = YES;
    }else{
        isCaptureds = NO;
    }
}

.

资料:

【iOS截屏防护】担心App内容被截屏泄露吗?

如果觉得本文有用,可以在下方点个赞。如果发现有遗漏或不对的地方,请在下方留言~