Overlay an image when app is inactive

Viewed 1287

I'm using these code to

1) overlay an image when the app is inactive (double tap the home button twice).

2) Remove the image when the app is active (reopen the app)

In appdelegate.h file:

@property (nonatomic, strong) UIImageView *splashScreenImageView;

In appdelegate.m file:

- (void)applicationWillResignActive:(UIApplication *)application
{
    UIImage *splashScreenImage = [UIImage imageNamed:@"BackgroundScreenCaching"];
    _splashScreenImageView = [[UIImageView alloc] initWithImage:splashScreenImage];
    [self.window addSubview:_splashScreenImageView];
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    if(_splashScreenImageView != nil) {
        [_splashScreenImageView removeFromSuperview];
        _splashScreenImageView = nil;
    }
}

Problem:

However, SOMETIME when pressing the home button twice, the iOS still caches the app screen with sensitive information instead of the overlay image in iOS 11. Tested no issue in iOS10.

Updated

Issue still persist after changing to this:

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

    BOOL result = [super application:application didFinishLaunchingWithOptions:launchOptions];
...
    UIImage *splashScreenImage = [UIImage imageNamed:@"BackgroundScreenCaching"];
    _splashScreenImageView = [[UIImageView alloc] initWithImage:splashScreenImage];
    [_splashScreenImageView setFrame:self.window.bounds];


    return result;
}


- (void)applicationDidBecomeActive:(UIApplication *)application
{
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    if(_splashScreenImageView != nil) {
        [_splashScreenImageView removeFromSuperview];
    }
}

- (void)applicationWillResignActive:(UIApplication *)application
{
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
    [self.window addSubview:_splashScreenImageView];
}
4 Answers
Related