iOS 8:移至背景前,先从视图中删除敏感信息 [英] iOS 8: Remove sensitive information from views before moving to the background

查看:124
本文介绍了iOS 8:移至背景前,先从视图中删除敏感信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iOS 7中,当应用程序进入后台时(订阅UIApplicationDidEnterBackgroundNotification),我的应用程序显示了一个身份验证屏幕.身份验证控制器删除了敏感信息,因此后台屏幕截图未显示任何用户信息.在iOS 8中,此功能不再起作用.现在,背景屏幕截图显示了用户上次在其中使用的视图,而不是身份验证控制器...即使应用重新回到前台时,身份验证控制器仍处于活动状态.

In iOS 7 my app presented an authentication screen when the app went into the background (by subscribing to UIApplicationDidEnterBackgroundNotification). The authentication controller removed sensitive information so the background screenshot did not show any user info. In iOS 8 this does not work anymore. The background screenshot now shows the view the user was last working in and not the authentication controller... even though when the app comes back into the foreground the authentication controller is active.

我现在找到了解决方法.我可以使用name:UIApplicationWillResignActiveNotification而不是使用UIApplicationDidEnterBackgroundNotification,但这会在用户离开应用程序时引起闪烁.

I found a work around for now. Instead of using UIApplicationDidEnterBackgroundNotification I can use name:UIApplicationWillResignActiveNotification however this causes a flash as the user leaves the app.

这是错误还是苹果提供了一种新的方法,可以在移至后台之前从视图中删除敏感信息.

Is this a bug or did apple provide a new way to remove sensitive information from views before moving to the background.

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

Note: putting ignoreSnapshotOnNextApplicationLaunch in applicationWillResignActive: and applicationDidEnterBackground: did not help.

更新:创建了错误报告

推荐答案

与@ Gurudev0777类似的方法,但是使用UIBlurEffect来遮盖内容,并且没有担心不同设备屏幕指标的缺点.应用程序委托:

Similar approach to @Gurudev0777, but uses UIBlurEffect instead to obscure the content, and doesn't have the downside of worrying about different device screen metrics. Application delegate:

#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];
        }];
    }
}

像魅力一样工作...

works like a charm...

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

Edited 5/18/2015: Thanks @Simeon Rice for observation about modal dialogs, revised to add blur view to self.window instead of rootViewController.view

修改日期:2016年8月23日:感谢@tpankake的观察:自动调整大小的蒙版.

Edited 8/23/2016: Thanks @tpankake for observation re: auto-resizing mask.

这篇关于iOS 8:移至背景前,先从视图中删除敏感信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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