iOS7以后当用户同时按下home键和锁屏键进行截取屏幕后系统会发送UIApplicationUserDidTakeScreenshotNotification通知,只需要在主线程中注册该通知,就可以捕获该截屏操作。
OC代码:
NSOperationQueue *mainQueue = [NSOperationQueue mainQueue];
[[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationUserDidTakeScreenshotNotification
object:nil
queue:mainQueue
usingBlock:^(NSNotification *note) {
// executes after screenshot
}];
swift代码:
let mainQueue = NSOperationQueue.mainQueue()
NSNotificationCenter.defaultCenter().addObserverForName(UIApplicationUserDidTakeScreenshotNotification,
object: nil,
queue: mainQueue) { notification in
// executes after screenshot
}
更多可查看stackoverflow上关于该问题的讨论。