iOS 截屏监听
苹果有提供方法,可以注册监听,当用户有截屏操作的时候会通知我们:
1、注册:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didTakeScreenshot:) name:UIApplicationUserDidTakeScreenshotNotification object:nil];
2、回调:
- (void)didTakeScreenshot:(NSNotification *)notification {
}
3、再次一并献上截屏数据获取
- (NSData*)screenshotWithRect:(CGRect)rect{
UIView *view = [UIApplication sharedApplication].windows[0].rootViewController.view;
UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, [UIScreen mainScreen].scale);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return UIImagePNGRepresentation(image);
}
本文地址:https://blog.csdn.net/jiangziwei/article/details/112556356