Created
February 23, 2020 04:34
-
-
Save denisoliveira/7e8db4aa56340ed81173b206a60c7b76 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// UIApplication+SplashOptions.h | |
#import <UIKit/UIKit.h> | |
@interface UIApplication (SplashOptions) | |
- (void)clearLaunchScreenCache; | |
@end | |
// UIApplication+SplashOptions.h | |
#import "UIApplication+SplashOptions.h" | |
@implementation UIApplication (SplashOptions) | |
- (void)clearLaunchScreenCache { | |
NSFileManager *fileManager = [NSFileManager defaultManager]; | |
NSString *path = [NSString stringWithFormat:@"%@%@", NSHomeDirectory(), @"/Library/SplashBoard"]; | |
NSError *error; | |
if ([fileManager removeItemAtPath:path error:&error]) { | |
NSLog(@"Success to delete launch screen cache"); | |
} | |
else { | |
NSLog(@"Failed to delete launch screen cache: %@", error); | |
} | |
} | |
@end | |
// AppDelegate.m | |
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { | |
[self clearCacheLogoIfNeed:application]; | |
return YES; | |
} | |
- (void)clearCacheLogoIfNeed:(UIApplication *)application { | |
NSDictionary *info = [[NSBundle mainBundle] infoDictionary]; | |
NSString *appVersion = [NSString stringWithFormat:@"%@ (%@)", | |
[info objectForKey:@"CFBundleShortVersionString"], | |
[info objectForKey:@"CFBundleVersion"]]; | |
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; | |
NSString *lastAppVersion = [userDefaults stringForKey:@"LAST_APP_VERSION"]; | |
if (![appVersion isEqualToString:lastAppVersion]) { | |
[application clearLaunchScreenCache]; | |
[userDefaults setObject:appVersion forKey:@"LAST_APP_VERSION"]; | |
[userDefaults synchronize]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment