在 iOS 7 多任务切换器中控制屏幕截图 [英] Controlling the screenshot in the iOS 7 multitasking switcher

查看:20
本文介绍了在 iOS 7 多任务切换器中控制屏幕截图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找有关 iOS 7 中新的多任务切换器的一些信息,尤其是当应用程序进入休眠状态时操作系统所截取的屏幕截图.

I've been trying to find some information regarding the new multitasking switcher in iOS 7 and especially the screenshot that the OS takes when the app is going into hibernation.

有什么办法可以完全关闭这个功能或截图吗?或者我可以从切换器中完全隐藏该应用程序吗?该应用需要在后台运行,但我们不想显示该应用的任何屏幕截图.

Is there any way to completely turn off this feature or screenshot? Or can I hide the app altogether from the switcher? The app needs to run in the background, but we do not want to show any screenshot from the app.

该屏幕截图可能存在安全风险,请按照银行应用程序的思路思考,其中您的卡号或帐户摘要可供双击设备上的主页按钮的任何人使用.

The screenshot is potentially a security-risk, think along the lines for banking-apps where your card number or account summary will be available to anyone that double-click on the home button on the device.

有人对此有任何见解吗?谢谢.

Anyone with any insight into this? Thanks.

推荐答案

准备你的 UI要在后台运行,Apple 说:

In Preparing Your UI to Run in the Background, Apple says:

在您的应用程序进入后台并且您的委托方法返回后的某个时刻,UIKit 会拍摄您应用程序当前用户界面的快照.系统在应用切换器中显示生成的图像.当您的应用返回前台时,它还会临时显示图像.

Prepare Your UI for the App Snapshot

At some point after your app enters the background and your delegate method returns, UIKit takes a snapshot of your app’s current user interface. The system displays the resulting image in the app switcher. It also displays the image temporarily when bringing your app back to the foreground.

您应用的 UI 不得包含任何敏感的用户信息,例如密码或信用卡号.如果您的界面包含此类信息,请在进入后台时将其从您的视图中删除.此外,关闭使应用程序内容变得模糊的警报、临时界面和系统视图控制器.快照代表您的应用程序的界面,应该是用户可识别的.当您的应用返回前台时,您可以根据需要恢复数据和视图.

Your app’s UI must not contain any sensitive user information, such as passwords or credit card numbers. If your interface contains such information, remove it from your views when entering the background. Also, dismiss alerts, temporary interfaces, and system view controllers that obscure your app’s content. The snapshot represents your app’s interface and should be recognizable to users. When your app returns to the foreground, you can restore data and views as appropriate.

请参阅技术问答 QA1838:防止敏感信息出现在任务切换器

除了隐藏/替换敏感信息之外,您可能还想通过 ignoreSnapshotOnNextApplicationLaunch,其文档说:

In addition to obscuring/replacing sensitive information, you might also want to tell iOS 7 to not take the screen snapshot via ignoreSnapshotOnNextApplicationLaunch, whose documentation says:

如果您觉得重新启动应用时快照无法正确反映应用的用户界面,您可以调用 ignoreSnapshotOnNextApplicationLaunch 以防止拍摄该快照图像.

If you feel that the snapshot cannot correctly reflect your app’s user interface when your app is relaunched, you can call ignoreSnapshotOnNextApplicationLaunch to prevent that snapshot image from being taken.

话虽如此,屏幕快照似乎仍在拍摄,因此我提交了错误报告.但您应该进一步测试,看看使用此设置是否有帮助.

Having said that, it appears that the screen snapshot is still taken and I have therefore filed a bug report. But you should test further and see if using this setting helps.

如果这是一个企业应用程序,您可能还想查看 限制有效负载配置文件参考.

If this was an enterprise app, you might also want to look into the appropriate setting of allowScreenShot outlined in the Restrictions Payload section of the Configuration Profile Reference.

这是一个实现我所需要的实现.你可以展示你自己的 UIImageView,或者你可以使用委托协议模式来隐藏机密信息:

Here is an implementation that achieves what I needed. You can present your own UIImageView, or your can use a delegate-protocol pattern to obscure the confidential information:

//  SecureDelegate.h

#import <Foundation/Foundation.h>

@protocol SecureDelegate <NSObject>

- (void)hide:(id)object;
- (void)show:(id)object;

@end

然后我给了我的应用委托一个属性:

I then gave my app delegate a property for that:

@property (weak, nonatomic) id<SecureDelegate> secureDelegate;

我的视图控制器设置了它:

My view controller sets it:

- (void)viewDidLoad
{
    [super viewDidLoad];

    AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
    delegate.secureDelegate = self;
}

视图控制器显然实现了该协议:

The view controller obviously implements that protocol:

- (void)hide:(id)object
{
    self.passwordLabel.alpha = 0.0;
}

- (void)show:(id)object
{
    self.passwordLabel.alpha = 1.0;
}

最后,我的应用委托利用了这个协议和属性:

And, finally, my app delegate avails itself of this protocol and property:

- (void)applicationWillResignActive:(UIApplication *)application
{
    [application ignoreSnapshotOnNextApplicationLaunch];  // this doesn't appear to work, whether called here or `didFinishLaunchingWithOptions`, but seems prudent to include it

    [self.secureDelegate hide:@"applicationWillResignActive:"];  // you don't need to pass the "object", but it was useful during my testing...
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    [self.secureDelegate show:@"applicationDidBecomeActive:"];
}

注意,我使用的是 applicationWillResignActive 而不是建议的 applicationDidEnterBackground,因为正如其他人指出的那样,双击主页按钮时不会调用后者应用程序运行时.

Note, I'm using applicationWillResignActive rather than the advised applicationDidEnterBackground, because, as others have pointed out, the latter is not called when double tapping on the home button while the app is running.

我希望我可以使用通知来处理所有这些,而不是委托协议模式,但在我有限的测试中,通知没有及时处理,但上述模式工作正常.

I wish I could use notifications to handle all of this, rather than the delegate-protocol pattern, but in my limited testing, the notifications aren't handled in a timely-enough manner, but the above pattern works fine.

这篇关于在 iOS 7 多任务切换器中控制屏幕截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆