直接上代碼, 就 一個(gè)通知的方法
?NSOperationQueue *mainQueue = [NSOperationQueue mainQueue];
? ? [[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationUserDidTakeScreenshotNotification
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? object:nil
?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? queue:mainQueue
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? usingBlock:^(NSNotification*note) {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //截屏已經(jīng)發(fā)生,可進(jìn)行相關(guān)提示處理
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? UIAlertView*alert= [[UIAlertViewalloc]initWithTitle:nilmessage:@"安全提醒]內(nèi)含付款碼,只適合當(dāng)面使用。不要截圖或分享給他人以保障資金安全"delegate:selfcancelButtonTitle:@"確定"otherButtonTitles:nil,nil];
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? [alertshow];
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? }];
用完之后記得 銷毀通知
- (void)dealloc{
? ? //離開(kāi)當(dāng)前控制器 ?最好移除通知
? ? [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationUserDidTakeScreenshotNotification object:nil];
}