Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 8: Remove sensitive information from views before moving to the background

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.

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.

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

Update: created a bug report

like image 758
datinc Avatar asked Sep 11 '14 18:09

datinc


1 Answers

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...

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

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

like image 69
CSmith Avatar answered Sep 22 '22 08:09

CSmith