iOS防止用户截屏

NSOperationQueue *mainQueue = [NSOperationQueuemainQueue];
    [[NSNotificationCenterdefaultCenter]addObserverForName:UIApplicationUserDidTakeScreenshotNotification                                                       object:nilqueue:mainQueueusingBlock:^(NSNotification *note){
        
        [selfjiePing];
    
     }];


-(void)jiePing
{
    UIAlertView *alertView=[[UIAlertViewalloc]initWithTitle:nilmessage:@"[安全提醒]内含付款码,只适合当面使用。不要截图或分享给他人以保障资金安全。"delegate:selfcancelButtonTitle:@"绝不给别人"otherButtonTitles:@"仅我自己用",nil];
    alertView.tag=105;
    [alertView show];
    

}

//这种写法会导致整个程序任何一个界面截图都会有弹出提示框,因为根本就没有指定哪个控制器,而且是一直在主线程里面
NSOperationQueue *mainQueue = [NSOperationQueuemainQueue];

  [[NSNotificationCenter defaultCenter]addObserver:selfselector:@selector(jiePing)name:UIApplicationUserDidTakeScreenshotNotification  object:nil];  //这个写法是针对于当前控制器

离开当前控制器的时候  最好移除通知
 [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector( jiePing) object:nil];

    [[NSNotificationCenter defaultCenter] removeObserver:selfname:UIApplicationUserDidTakeScreenshotNotification object:nil];

原文链接: http://blog.csdn.net/ios_xumin/article/details/51788544

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值