防止敏感信息出现在任务切换器中-Apple代码不起作用-iOS 8故障?

SAH*_*AHM 5 background task-switching sensitive-data ios8

本文档:防止敏感信息出现在任务切换器中,它描述了一种在applicationDidEnterBackground中显示视图控制器的方法,以便在任务切换器中隐藏关键信息:

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // Your application can present a full screen modal view controller to
    // cover its contents when it moves into the background. If your
    // application requires a password unlock when it retuns to the
    // foreground, present your lock screen or authentication view controller here.

    UIViewController *blankViewController = [UIViewController new];
    blankViewController.view.backgroundColor = [UIColor blackColor];

    // Pass NO for the animated parameter. Any animation will not complete
    // before the snapshot is taken.
    [self.window.rootViewController presentViewController:blankViewController animated:NO completion:NULL];
}
Run Code Online (Sandbox Code Playgroud)

但是,在iOS 8中,此确切的代码无法正常工作,只有在应用再次激活后,才会显示非常简单的纯黑视图控制器。任务切换器显示敏感信息,没有任何隐藏内容。这段代码中没有动画,所以我听不懂-为什么会这样?

Bre*_*ent 2

在 iOS 8 中,在截取屏幕截图之前,应用程序没有足够的时间来显示视图控制器。

对我有用的修复方法是在 applicationDidEnterBackground 末尾引入一个小的运行循环。

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    UIViewController *blankViewController = UIViewController.new;
    blankViewController.view.backgroundColor = UIColor.blackColor;
    [self.window.rootViewController presentViewController:blankViewController animated:NO completion:NULL];
    [NSRunLoop.currentRunLoop runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.5]];
}
Run Code Online (Sandbox Code Playgroud)