I found a difficult way and it works with iOS 11 or iOS 10.
In the Appdelegate.m file:
@implementation AppDelegate { UIImageView *splashScreenImageView; UIViewController *viewController; }
Add this code to doneFinishLaunchingWithOptions to set the image frame and updates
splashScreenImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)]; splashScreenImageView.image = [UIImage imageNamed:@"BackgroundScreenCaching"];
Implement this method to get the top view controller
- (UIViewController *)topViewController{ return [self topViewController:[UIApplicationsharedApplication].keyWindow.rootViewController]; } - (UIViewController *)topViewController:(UIViewController *)rootViewController { if (rootViewController.presentedViewController == nil) { return rootViewController; } if ([rootViewController.presentedViewController isKindOfClass:[UINavigationController class]]) { UINavigationController *navigationController = (UINavigationController *)rootViewController.presentedViewController; UIViewController *lastViewController = [[navigationController viewControllers] lastObject]; return [self topViewController:lastViewController]; } UIViewController *presentedViewController = (UIViewController *)rootViewController.presentedViewController; return [self topViewController:presentedViewController]; }
Now in the applicationWillResignActive application, first get the top viewController and set splashScreenImageView in this view as a subview
- (void)applicationWillResignActive:(UIApplication *)application { viewController = [self topViewController]; [viewController.view addSubview:splashScreenImageView]; }
Finally, in applicationDidBecomeActive , when the application is open, first remove the overlay image and open the application
- (void)applicationDidBecomeActive:(UIApplication *)application { [splashScreenImageView removeFromSuperview]; }
These tricks will work.
source share