iOS 8:在移到后台之前从视图中删除敏感信息

iOS 8:在移到后台之前从视图中删除敏感信息,ios,objective-c,ios8,Ios,Objective C,Ios8,在iOS 7中,当应用程序进入后台时(通过订阅UIApplicationIdentinterBackgroundNotification),我的应用程序显示了一个身份验证屏幕。身份验证控制器删除了敏感信息,因此背景屏幕截图没有显示任何用户信息。在iOS 8中,这不再有效。背景屏幕截图现在显示用户上次使用的视图,而不是身份验证控制器。。。即使当应用程序返回前台时,身份验证控制器仍处于活动状态 我现在找到了一份工作。我可以使用name:uiapplicationwillresignactivatio

在iOS 7中,当应用程序进入后台时(通过订阅
UIApplicationIdentinterBackgroundNotification
),我的应用程序显示了一个身份验证屏幕。身份验证控制器删除了敏感信息,因此背景屏幕截图没有显示任何用户信息。在iOS 8中,这不再有效。背景屏幕截图现在显示用户上次使用的视图,而不是身份验证控制器。。。即使当应用程序返回前台时,身份验证控制器仍处于活动状态

我现在找到了一份工作。我可以使用
name:uiapplicationwillresignactivationification
而不是使用
uiapplicationidentinterbackgroundnotification
,但是这会在用户离开应用程序时导致闪烁

这是一个bug还是苹果提供了一种新的方法,在移动到后台之前从视图中删除敏感信息

注意:将
ignoreSnapshotOnNextApplicationLaunch
放入
applicationWillResignActive:
applicationidenterbackground:
没有帮助


更新:创建了一个bug报告

类似于@Gurudev0777的方法,但使用UIBlurEffect来隐藏内容,并且没有担心不同设备屏幕指标的缺点。申请代表:

here we are putting an imageview while the app animate to background -
-(void)applicationWillResignActive:(UIApplication *)application
{
    imageView = [[UIImageView alloc]initWithFrame:[self.window frame]];
    [imageView setImage:[UIImage imageNamed:@"Default@2x.png"]];
    [self.window addSubview:imageView];
}

Here is the code to remove the imageview:
- (void)applicationDidBecomeActive:(UIApplication *)application
{
    if(imageView != nil) {
        [imageView removeFromSuperview];
        imageView = nil;
    }
}
It is working and tested many times.
*** Please test this scenario into the device not in simulator.
#define MY_BACKGROUND_SCREEN_TAG 1001//or any random but UNIQUE number.

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // Visual effect view for blur
    UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
    UIVisualEffectView *blurView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
    [blurView setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
    [blurView setFrame:self.window.frame];
    blurView.tag = MY_BACKGROUND_SCREEN_TAG;

    [self.window addSubview:blurView];
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    // remove blur view if present
    UIView *view = [self.window viewWithTag:MY_BACKGROUND_SCREEN_TAG];
    if (view != nil)
    {
        [UIView animateWithDuration:0.2f animations:^{
            [view setAlpha:0];

        } completion:^(BOOL finished) {
            [view removeFromSuperview];
        }];
    }
}
工作起来很有魅力

2015年5月18日编辑:感谢@Simeon Rice对模态对话框的观察,修改为将模糊视图添加到self.window而不是rootViewController.view

编辑于2016年8月23日:感谢@tpankake提供有关自动调整大小掩码的观察。

-(无效)应用程序将resignactive:(UIApplication*)应用程序
{
//当应用转到后台时显示飞溅
UIImageView*imageView=[[UIImageView alloc]initWithFrame:self.window.bounds];
imageView.tag=101;//分配图像标记
//imageView.backgroundColor=[UIColor redColor];
[imageView setImage:[UIImage ImageName:@“Default.png”];
[UIApplication.sharedApplication.keyWindow.subviews.lastObject addSubview:imageView];
}
-(无效)应用IDBECOMEACTIVE:(UIApplication*)应用
{
//当应用程序转到前台时清除飞溅
UIImageView*imageView=(UIImageView*)[UIApplication.sharedApplication.keyWindow.subviews.lastObject viewWithTag:101];//按图像标记查找图像
[imageView从SuperView移除];
}

我会将其作为一个bug提交给苹果,只是为了确保这不是一个疏忽。最坏的情况是,您的错误报告无效,他们将丢弃它。Hmmm。我的应用程序在退出active时总是清除敏感数据。在我读到这篇文章之前,我没有注意到在iOS 8下从我的应用程序中点击主页按钮时出现的“闪光”。bug报告听起来是个好主意。有关于bug报告的消息吗?这似乎是个大问题。不。。。报告保持不变。不幸的是,当显示全屏模式时(至少在iPhone上),此高质量解决方案不会模糊-为了解决此问题,我将模糊视图添加到
self.window
,而不是根视图控制器的视图。我喜欢此解决方案,它工作得很好。有一件小事需要注意。在iPad上,如果用户点击主页,然后更改iPad方向,然后访问应用程序切换器并选择模糊应用程序,则模糊视图不会因为方向更改而模糊整个应用程序屏幕截图。要解决此问题,只需将自动调整大小遮罩添加到模糊视图
blurView.autoresizingMask=UIViewAutoresizingFlexibleWidth | uiviewautoresizingflexiblewhight谢谢您的解决方案。我们正在applicationWillResignActive中为我们的应用程序添加一个遮罩视图:-在iOS 8中,当双击home按钮时,它会在预览中立即显示遮罩。在iOS 9+(也在10测试版中测试)中,当双击时,它不会立即屏蔽。当应用程序进入后台,然后双击home,它被屏蔽。有人知道如何马上制作面具吗?我想他们在iOS 9之后改变了机制。