防止 iOS 在进入后台之前截取应用程序的屏幕截图
大家可能都知道,iOS 在将应用程序放入后台之前会对其进行屏幕截图。这通常是为了更好的用户体验,例如快速动画以恢复应用程序等。我不希望我的应用程序屏幕截图存储在设备上,但我希望多任务处理仍然存在。
我想出了一个解决方案,但我不确定我是否朝着正确的方向前进。因此,当调用 applicationDidEnterBackground
时,我放入了操作系统将捕获的覆盖图像,一旦应用程序进入前台,我将删除该覆盖图像。我不确定这是否会起作用,但我正在实施它。同时,对此的任何其他想法都将帮助我找出解决此问题的最佳方法。
You all might know that iOS takes a screen shot of your application before throwing it into the background. This is usually for a better User experience like quick animation to bring the app back and so on. I don't want my app screen shot to be stored on the device, but I want the multitasking to still exist.
I came out with a solution but I'm not sure if I'm heading in the right direction. So, when the applicationDidEnterBackground
is called -- I put in an overlay image that will be captured by the OS, and once the app enters foreground, I will remove the overlay. I'm not sure if this is going to work but I'm on my way to implement this. Meanwhile, any other thoughts on this will help me figure out the optimal way of attacking this issue.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
你走在正确的轨道上。这是 Apple 推荐的方法,如中所述iOS 应用程序编程指南:
You are on the right track. This is Apple's recommended way to do this as noted in the iOS Application Programming Guide:
需要在应用程序生命周期方法中编写代码,这里我们在应用程序动画到背景时放置一个
imageView
:这是删除
imageView
的代码:它正在工作并经过适当测试。
Need to write the code in Application life cycle methods, here we are putting an
imageView
while the app animate to background :Here is the code to remove the
imageView
:It is working and properly tested.
我遇到了同样的问题,我的研究使我得到了以下答案:
在应用程序进入后台之前设置模糊的屏幕覆盖层,一旦应用程序变为活动状态,请删除此覆盖层
如果是 iOS 7 或更高版本,您可以使用该功能
ignoreSnapshotOnNextApplicationLaunch
请参阅苹果文档:
<一href="https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplication_Class/Reference/Reference.html#//apple_ref/occ/instm/UIApplication/ignoreSnapshotOnNextApplicationLaunch ">https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplication_Class/Reference/Reference.html#//apple_ref/occ/instm/UIApplication/ignoreSnapshotOnNextApplicationLaunch
我希望这对某人有帮助。
I came across the same issue, and my research has lead me to the following answers:
set a blurry screen overlay before the app goes in the background and once the app becomes active remove this overlay
if it is iOS 7 or later you can use the function
ignoreSnapshotOnNextApplicationLaunch
See in apple documentation:
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplication_Class/Reference/Reference.html#//apple_ref/occ/instm/UIApplication/ignoreSnapshotOnNextApplicationLaunch
I hope this helps somebody.
AppDelegate 中的工作方法,swift 4.2:
在哪里:
在需要的委托方法中调用这些方法:
Working methods in AppDelegate, swift 4.2:
Where is:
Call these methods in needed delegate methods:
你的方法是完全正确的,也是唯一的方法。放置一个覆盖视图并稍后将其删除。如果您的应用程序显示您不希望以图像格式缓存的敏感数据,则执行此操作是有效的。
Your approach is exactly the correct and only way to do it. Place an overlay view and remove it later. It is valid to do this if your app shows sensitive data that you don't want to be cached in image format anywhere.
苹果文档
https://developer.apple.com/library/archive/qa/ qa1838/_index.html
注意: -applicationDidEnterBackground: 的实现不应启动任何动画(将 NO 传递给任何animated: 参数)。从此方法返回后,将立即捕获应用程序窗口的快照。在拍摄快照之前动画不会完成。
在我声明的 swift 4.2 应用程序委托中转换了 Apple 代码
Apple Doc
https://developer.apple.com/library/archive/qa/qa1838/_index.html
Note: Your implementation of -applicationDidEnterBackground: should not start any animations (pass NO to any animated: parameter). The snapshot of your application's window is captured immediately upon returning from this method. Animations will not complete before the snapshot is taken.
Converted Apple code in swift 4.2 App delegate i declared
Depak Kumar 帖子的改进:
创建一个属性
UIImage *snapShotOfSplash;
Improvement in Depak Kumar post :
Make a property
UIImage *snapShotOfSplash;
在后台和反向操作时使用一些动画实现
Implementation with some animation while going in background and reverse action
迅捷4.0版本。
要使用自定义图标,
首先在 AppDelegate 顶部添加此行
并添加:
黑色背景
swift 4.0 version.
for use custom icon
first add this line at top of AppDelegate
and add this:
background with black color
在 iOS 7 中,您可以使用
allowScreenShot
来完全停止该功能。请参阅: Apple 开发者:配置文件参考:
In iOS 7 you could use the
allowScreenShot
to stop the ability all together.See: Apple Developer: Configuration Profile Reference: