How to detect screenshots on iOS (like SnapChat)
2013-08-29 15:06
585 查看
http://blog.chpwn.com/post/38491252231
A number of Stack Overflow questions
were having issues with this, so I figured I’d explain. From reverse engineering, this is the exact method used by SnapChat, but it’s also pretty much what I’d have done myself.
The process is pretty simple, and relies on a quirk of iOS: taking a screenshot cancels all touches on the screen. Because of that, anything that you want to protect will require you to have the user to touch the screen to see. If that works for your purposes,
the general solution is to simply intercept the touch cancellation, and quickly remove any sensitive information from the screen. If you’re also implementing a screenshot counter, as with SnapChat, you will also need to take into account the other cases when
a touch might be cancelled: from a system gesture (Notification Center or the iPad’s multitasking gestures), or by activating other pieces of system UI (the power down menu, or the multitasking switcher).
On a technical level, the two basic pieces are
if you want) and
you should hide your sensitive information when the gesture recognizer’s
and if you want to track the number of screenshots, increment a counter. Then, in the
decrement that counter when you receive the
to account for the other possibilities for a cancelled touch. You might also need to handle other situations where a touch could be cancelled, if other parts of your app might cause that to happen.
A number of Stack Overflow questions
were having issues with this, so I figured I’d explain. From reverse engineering, this is the exact method used by SnapChat, but it’s also pretty much what I’d have done myself.
The process is pretty simple, and relies on a quirk of iOS: taking a screenshot cancels all touches on the screen. Because of that, anything that you want to protect will require you to have the user to touch the screen to see. If that works for your purposes,
the general solution is to simply intercept the touch cancellation, and quickly remove any sensitive information from the screen. If you’re also implementing a screenshot counter, as with SnapChat, you will also need to take into account the other cases when
a touch might be cancelled: from a system gesture (Notification Center or the iPad’s multitasking gestures), or by activating other pieces of system UI (the power down menu, or the multitasking switcher).
On a technical level, the two basic pieces are
UILongPressGestureRecognizer(or
-touchesCancelled:withEvent:,
if you want) and
UIApplicationDelegate. In your long press handler,
you should hide your sensitive information when the gesture recognizer’s
stateis
UIGestureRecognizerStateCancelled,
and if you want to track the number of screenshots, increment a counter. Then, in the
UIApplicationDelegate,
decrement that counter when you receive the
-applicationWillEnterBackground:or
-applicationDidResignActive:notification
to account for the other possibilities for a cancelled touch. You might also need to handle other situations where a touch could be cancelled, if other parts of your app might cause that to happen.
相关文章推荐
- How to take screenshots on your Samsung Galaxy Tab 10.1
- How to Set a Custom Logon Screen Background on Windows 7, 8, or 10
- How to make DirectFB screenshots
- How to Customize UITabBar on iOS 5
- Hack Like a Pro: How to Kill and Disable Antivirus Software on a Remote PC
- 自定义UITabBar=How to Customize UITabBar on iOS 5
- Hack Like a Pro: How to Hack a Computer & Spy on Anyone, Part 1
- How to Turn on iOS Diagnostics and Send Crash Reports
- How to debug Javascript errors on iOS
- [WP7] How to press the mouse on a control, and detect MouseLeftButtonUp on another
- How to use on-screen virtual keyboard on Linux
- How to use CCRenderTexture for Motion Blur, Screenshots and Drawing Sketches
- How to share on Facebook obout iOS?
- How to Add Splash Screen in Your iOS App
- How to Customize UITabBar on iOS 5
- How to use Screen on Linux
- How to use Facebook iOS SDK on iOS 10
- How to Set Up DTrace to Detect PHP Scripting Problems on Oracle Linux
- How to run cpp-tests on iOS
- How to Make Great App Store Screenshots