App应用系统截屏提示UIApplicationUserDidTakeScreenshotNotification

App 的界面,如果是信息相对敏感的,可能存在被三方截屏、录屏软件截取的风险。可以通过获取系统截图通知进行提示当前使用用户。
实现原理是使用通知,即获取系统截屏时的通知UIApplicationUserDidTakeScreenshotNotification,并执行相关的方法。

代码示例如下:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    // 系统截屏通知
    [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(notificationScreenshot:) name:UIApplicationUserDidTakeScreenshotNotification object:nil];
    
    return YES;
}
- (void)notificationScreenshot:(NSNotification *)notification
{
    [[[UIAlertView alloc] initWithTitle:nil message:@"截屏有风险,请确保是本人操作~" delegate:nil cancelButtonTitle:@"知道了" otherButtonTitles:nil, nil] show];
}

截屏提示可以是针对某个界面,也可以针对整个App应用使用周期。如示例代码是针对整个应用的使用。

发布了804 篇原创文章 · 获赞 135 · 访问量 142万+

猜你喜欢

转载自blog.csdn.net/potato512/article/details/103693909