Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preventing snapshot view of your app when coming back from multi-tasking

The problem is this - My app lets you passcode protect itself. I use an interface just like passcode protecting the phone. This has always worked fine, until multi-tasking came along.

The passcode protection still works, but there is one issue. Apple does something special to make it look like our apps are loading quicker when they come back from the background. The os takes a picture of our screen just before the user leaves the app, and it displays that while the rest of the app is still loading.

The problem this causes is that someone trying to go to my app would see that image of the screen before the passcode protection kicked in. Granted, it's not much, but I don't think my users will like the idea of people being able to get even a little glimpse of their data.

How to stop that snapshot image from showing?

like image 642
Elijah Avatar asked Jun 04 '11 06:06

Elijah


3 Answers

I solved this. Here is the solution:

- (void)applicationDidEnterBackground:(UIApplication *)application{
    if (appHasPasscodeOn){
        UIImageView *splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0, 320, 480)];
        splashView.image = [UIImage imageNamed:@"Default.png"];
        [window addSubview:splashView];
        [splashView release];
    }
}

Default.png is a screenshot of my app with a blank screen (for me it's just a blank listview). The code above puts that in front of my real view right before the app goes into the background. So, when you come back to the app that is all you see. Voila.

like image 151
Elijah Avatar answered Nov 09 '22 09:11

Elijah


The marked answer works perfectly for me except that when the app becomes active again the splashView stays on screen. I just made it a property and added [splashView removeFromSuperview] into my applicationWillEnterForeground to fix it. In case anyone else gets similar behavior.

like image 38
user1715649 Avatar answered Nov 09 '22 08:11

user1715649


Here is the above solution in Swift 3.0:

lazy var splashImageView: UIImageView = {
    let splashImageView = UIImageView(frame: UIScreen.main.bounds)
    splashImageView.image = UIImage(named: "splash-view")
    return splashImageView
}()

func applicationDidEnterBackground(_ application: UIApplication) {
    window?.addSubview(splashImageView)
}

func applicationWillEnterForeground(_ application: UIApplication) {
   splashImageView.removeFromSuperview()
}
like image 40
Marijn Avatar answered Nov 09 '22 08:11

Marijn