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