Question

What exactly happens with an app when the user presses the home button? Does iOS make a snapshot of current app's state?

If I'm right, how to "slip in" another snapshot? I need it for showing the main iOS screen after user presses home button twice.

Was it helpful?

Solution 2

iOS takes screenshot before your application goes to background.

I got it from Apple's official documentation.

Remove sensitive information from views before moving to the background: When an app transitions to the background, the system takes a snapshot of the app’s main window, which it then presents briefly when transitioning your app back to the foreground. Before returning from your applicationDidEnterBackground: method, you should hide or obscure passwords and other sensitive personal information that might be captured as part of the snapshot.

So, Here We can hide our "sensitive personal information" and the system takes a snapshot of the app’s main window and we are not able to change its feature.

# sensitive personal information

  • Set a blurry screen overlay before the app goes in the background and once the app becomes active remove this overlay (check @cweinberger's answer).

  • If it is iOS 7 or later you can use the function ignoreSnapshotOnNextApplicationLaunch Also, allowScreenShot flag can be explored in Restrictions Payload.

For deeply read about it Then this is the best documentation.

OTHER TIPS

In order to achieve that, you could add a subview (i.e. ImageView with an image of your main screen) to your window in - (void)applicationDidEnterBackground:(UIApplication *)application.

When coming back (in - (void)applicationWillEnterForeground:(UIApplication *)application) you have to remove the subview.

However, Apple recommends to always show the latest state of the app (best user experience).

Example of AppDelegate implementation:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    /* other code */

    self.overlayView = [[UIImageView alloc] initWithFrame:self.window.bounds];
    self.overlayView.image = [UIImage imageNamed:@"mainscreen_screenshot.png"];

    /* other code */
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    [self.window addSubview:self.overlayView];
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    [self.overlayView removeFromSuperview];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top