アプリスナップチャットApp Store で入手できる は、自動消去機能付きの画像を共有できるアプリです。画像は X 秒間しか表示できません。画像が表示されているときに、ホーム キーと電源キーの組み合わせを使用してスクリーンショットを撮ろうとすると、送信者にスクリーンショットを撮ろうとしたことが通知されます。
SDK のどの部分で、ユーザーがスクリーンショットを撮っていることを検出できますか? これが可能だとは知りませんでした。
ベストアンサー1
iOS 7 以降、他の回答は当てはまらなくなりました。Apple は、touchesCancelled:withEvent:
ユーザーがスクリーンショットを撮っても呼び出されないようにしました。
これはSnapchatを完全に破壊することになるので、新しい解決策のベータ版がいくつか追加されました。今では、NSNotificationCenterを使用してオブザーバーを追加するだけで解決できます。UIApplicationUserDidTakeScreenshot通知。
次に例を示します。
目的 C
NSOperationQueue *mainQueue = [NSOperationQueue mainQueue];
[[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationUserDidTakeScreenshotNotification
object:nil
queue:mainQueue
usingBlock:^(NSNotification *note) {
// executes after screenshot
}];
迅速
NotificationCenter.default.addObserver(
forName: UIApplication.userDidTakeScreenshotNotification,
object: nil,
queue: .main) { notification in
//executes after screenshot
}