me2*_*me2 128 screenshot ios
App Store上的应用程序Snapchat是一款应用程序,可让您在其上分享带有自毁功能的图片.您只能查看X秒的照片.如果您在使用家用电源键组合显示图片时尝试截取屏幕截图,它会告诉发件人您尝试截取屏幕截图.
SDK的哪个部分可以让您检测到用户正在截取屏幕截图?我不知道这是可能的.
Mic*_*lum 350
从iOS 7开始,其他答案已不再适用.touchesCancelled:withEvent:
当用户截取屏幕截图时,Apple已经不再调用了它.
这将完全打破Snapchat,因此增加了一个新解决方案中的几个beta.现在,解决方案就像使用NSNotificationCenter将观察者添加到UIApplicationUserDidTakeScreenshotNotification一样简单.
这是一个例子:
NSOperationQueue *mainQueue = [NSOperationQueue mainQueue];
[[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationUserDidTakeScreenshotNotification
object:nil
queue:mainQueue
usingBlock:^(NSNotification *note) {
// executes after screenshot
}];
Run Code Online (Sandbox Code Playgroud)
NotificationCenter.default.addObserver(
forName: UIApplication.userDidTakeScreenshotNotification,
object: nil,
queue: .main) { notification in
//executes after screenshot
}
Run Code Online (Sandbox Code Playgroud)
por*_*ast 22
我找到了答案!! 截屏会中断屏幕上的任何触摸.这就是为什么Snapchat需要持有才能看到图片.参考:http://tumblr.jeremyjohnstone.com/post/38503925370/how-to-detect-screenshots-on-ios-like-sn
Esq*_*uth 11
继承人如何在Swift中使用闭包:
func detectScreenShot(action: () -> ()) {
let mainQueue = NSOperationQueue.mainQueue()
NSNotificationCenter.defaultCenter().addObserverForName(UIApplicationUserDidTakeScreenshotNotification, object: nil, queue: mainQueue) { notification in
// executes after screenshot
action()
}
}
detectScreenShot { () -> () in
print("User took a screen shot")
}
Run Code Online (Sandbox Code Playgroud)
Swift 4.2
func detectScreenShot(action: @escaping () -> ()) {
let mainQueue = OperationQueue.main
NotificationCenter.default.addObserver(forName: UIApplication.userDidTakeScreenshotNotification, object: nil, queue: mainQueue) { notification in
// executes after screenshot
action()
}
}
Run Code Online (Sandbox Code Playgroud)
这包含在以下标准函数中:
https://github.com/goktugyil/EZSwiftExtensions
免责声明:我的回购
斯威夫特 4+
NotificationCenter.default.addObserver(forName: UIApplication.userDidTakeScreenshotNotification, object: nil, queue: OperationQueue.main) { notification in
//you can do anything you want here.
}
Run Code Online (Sandbox Code Playgroud)
通过使用这个观察者,你可以发现用户何时截屏,但你无法阻止他。