2

My case is the following: I have a Cordova application that has to run on iOS. I have to prevent sensitive information from being shown in the app switcher when the app is being in background.

Apple provides this solution for native applications which doesn't seem to solve my problem, because it doesn't manipulate the web view in any way.

I wonder if I can natively place some static image covering the webview. As I understand the system takes a screenshot of the view right after the applicationDidEnterBackground: method is invoked.

This way the system will take a screenshot of the image I put on top instead of the actual content of the webview.

I'm not an experienced iOS developer and I will appreciate any suggestion.

Thanks.

Community
  • 1
  • 1
  • You could add a fullscreen div with an appropriate `z-index`, not native, but it'll work. [Detect If Browser Tab Has Focus](http://stackoverflow.com/questions/7389328/detect-if-browser-tab-has-focus) might be useful. – Huey Aug 07 '15 at 15:45
  • Thanks, but I have some concerns. Manipulating any web content is asynchronous to the native app lifecycle. So most certainly showing the blank div will not happen on time, or at least I cannot rely on that. – George Penchev Aug 10 '15 at 06:58

1 Answers1

1

It turned out apple's solution could fix the problem with a small edit from me.

Instead of implementing

- (void)applicationDidEnterBackground:(UIApplication *)application

I implemented

-(void)applicationWillResignActive:(UIApplication *)application

Then no matter if you hit the home button once or twice, it will cover the viewcontroller with the blank one just created.

-(void)applicationWillResignActive:(UIApplication *)application {
    UIViewController *blankViewController = [UIViewController new];

    //this is how to attach image
    UIImage *splashImage = [UIImage imageNamed:@"some image"];
    blankViewController.view.backgroundColor = [UIColor colorWithPatternImage: splashImage];

    // set some transition style
    blankViewController.modalTransitionStyle = UIModalTransitionStylePartialCurl;

    [self.window.rootViewController presentViewController:blankViewController animated:YES completion:NULL];
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{

    [self.window.rootViewController dismissViewControllerAnimated:YES completion:NULL];
}