【问题标题】:iOS 8: Remove sensitive information from views before moving to the backgroundiOS 8:在移动到后台之前从视图中删除敏感信息
【发布时间】:2014-09-11 18:25:49
【问题描述】:

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

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

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

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

更新:创建了一个错误报告

【问题讨论】:

  • 我会将其作为一个错误提交给 Apple,以确保这不是疏忽。最坏的情况是,您的错误报告无效,他们会丢弃它。
  • 嗯。我的应用程序在退出活动时总是清除敏感数据。在我阅读这篇文章之前,我没有注意到在 iOS 8 下从我的应用程序中点击 Home 按钮时出现“闪烁”。错误报告听起来是个好主意。
  • 关于错误报告的任何消息?这似乎是个大问题。
  • 不...报告保持不变。

标签: ios objective-c ios8


【解决方案1】:

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

#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 观察 re:自动调整大小的蒙版。

【讨论】:

  • 不幸的是,当呈现全屏模式时(至少在 iPhone 上),这种高质量的解决方案不会模糊 - 为了解决这个问题,我将模糊视图添加到 self.window 而不是根视图控制器的视图。
  • 我喜欢这个解决方案,效果很好。一件小事要注意。在 iPad 上,如果用户点击 home,然后更改 iPad 方向,然后访问应用程序切换器并选择模糊的应用程序,则由于方向更改,模糊视图不会模糊整个应用程序屏幕截图。要解决这个问题,只需将自动调整大小的蒙版添加到模糊视图 blurView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  • 感谢您的解决方案。我们在 applicationWillResignActive 中为我们的应用程序添加了一个遮罩视图: - 在 iOS 8 中,当双击主页按钮时,它会立即在预览中显示遮罩。在 iOS 9+ 中(也在 10 beta 中测试过),双击时,它不会立即屏蔽。当应用程序进入后台时,主页被双击,它被屏蔽了。有谁知道如何让它马上面具?我认为他们从 iOS 9 开始改变了机制。
【解决方案2】:
- (void)applicationWillResignActive:(UIApplication *)application
{
   // show splash when app goto background
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.window.bounds];

    imageView.tag = 101; // assign image tag
    //    imageView.backgroundColor = [UIColor redColor];
    [imageView setImage:[UIImage imageNamed:@"Default.png"]];

    [UIApplication.sharedApplication.keyWindow.subviews.lastObject addSubview:imageView];
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
// remove splash when app goto foreground
    UIImageView *imageView = (UIImageView *)[UIApplication.sharedApplication.keyWindow.subviews.lastObject viewWithTag:101]; // lookup image by image tag
    [imageView removeFromSuperview];
}

【讨论】:

    【解决方案3】:
    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.
    

    【讨论】:

      猜你喜欢
      • 2019-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多