microsoft / react-native-code-push

React Native module for CodePush
http://appcenter.ms
Other
8.99k stars 1.47k forks source link

[iOS] Subview stuck on top of view stack after code-push update/install #881

Closed joeferraro closed 7 years ago

joeferraro commented 7 years ago

Description

Hi, thanks for the great project. Fully appreciate this is probably an issue with our codebase, but figured I'd start here.

For the iOS app we're developing, we need to add screen obfuscation when the app is backgrounded because it contains sensitive information. We are using applicationWillResignActive and applicationDidBecomeActive to show/hide a blurred subview. The screen obfuscation works great until the app receives and installs a code-push update. The update is installed ON_NEXT_RESUME, so when the app is backgrounded and foregrounded, for some reason the update is installed but the BlurView is not removed (stuck on top of the view stack). The workaround for us is to swipe the app close and open it again. Any hints on what we might be doing wrong? Should we be detecting the code-push update install and forcibly removing the BlurView?

Reproduction

  1. Implement UIBlurEffect to obfuscate screen via applicationWillResignActive and applicationDidBecomeActive in AppDelegate
  2. react-native app should be configured with:
    const codePushOptions = { 
    checkFrequency: codePush.CheckFrequency.ON_APP_RESUME,
    installMode: codePush.InstallMode.ON_NEXT_RESUME,
    };
  3. Install app from store
  4. Push code-push update
  5. App receives update and is prepared to install it ON_NEXT_RESUME
  6. Background app
  7. Bring app to foreground
  8. Subview BlurView remains atop the view stack and obfuscates the screen

Additional Information

Sample AppDelegate.m

- (void)applicationWillResignActive:(UIApplication *)application {
    self.window.backgroundColor = [UIColor clearColor];

    UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleExtraLight];
    UIVisualEffectView *blurEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
    blurEffectView.frame = self.window.bounds;
    blurEffectView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

    blurEffectView.tag = 1234;
    blurEffectView.alpha = 0;
    [self.window addSubview:blurEffectView];
    [self.window bringSubviewToFront:blurEffectView];

    // fade in the view
    [UIView animateWithDuration:0.5 animations:^{
        blurEffectView.alpha = 1;
    }];
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // NSLog(@"Hiding blur");
    // grab a reference to our custom blur view
    UIView *blurEffectView = [self.window viewWithTag:1234];

    // fade away colour view from main view
    [UIView animateWithDuration:0.5 animations:^{
        blurEffectView.alpha = 0;
    } completion:^(BOOL finished) {
        // remove when finished fading
        [blurEffectView removeFromSuperview];
    }];
}
joeferraro commented 7 years ago

We have resolved this issue, but frankly, we're not sure how we did it. So I'll close this for now and report back if/when we determine the root cause. Thanks!