iOS13 设置LaunchScreen启动图片过程中黑屏

问题
iOS13要求LaunchScreen启动,过程中反复安装App,有时会出现启动图片黑屏情况。
原因
可能是由于App第一次启动的时候,iOS系统缓存了启动图片,以后App就一直用iOS系统缓存的启动图片。多次反复安装后,造成多个重名图片缓存,系统无法选择(bug??),造成黑屏。
解决
①清除缓存,重启系统。但是这种方式不太好,不可能让所有用户都去重启系统。
②更新缓存,修改启动图片名称,iOS系统识别到App的启动图片名称变更,就会去更新缓存。

以上仅仅是猜测,如果出现同样的问题可以试试看能否解决问题。如果有更详细的资料和尝试,欢迎分享。

参考:https://juejin.im/post/5ba4d640e51d45395d4edf61

后续

用代码清理App缓存

缓存目录:
iOS11:/AppData/Library/Caches/Snapshots
iOS13:/AppData/Library/SplashBoard/Snapshots

定义方法(swift):

import UIKit 
public extension UIApplication {
    
     
	func clearLaunchScreenCache() {
    
     
		do {
    
     
			try FileManager.default.removeItem(atPath: NSHomeDirectory()+"/Library/Caches/Snapshots") 
		} catch {
    
    
			print("Failed to delete launch screen cache: \(error)") 
		}
	}
}

调用方法(swift):

UIApplication.shared.clearLaunchScreenCache()

参照:Quick tip: clearing your app’s launch screen cache on iOS

定义方法(oc):

#import <UIKit/UIKit.h> 
@interface UIApplication (LaunchScreen) 
- (void)clearLaunchScreenCache; 
@end 
#import "UIApplication+LaunchScreen.h" 
@implementation UIApplication (LaunchScreen) 
- (void)clearLaunchScreenCache {
    
    
	NSError *error; 
	[NSFileManager.defaultManager removeItemAtPath:[NSString stringWithFormat:@"%@/Library/Caches/Snapshots",NSHomeDirectory()] error:&error];
	if (error) {
    
    
		NSLog(@"Failed to delete launch screen cache: %@",error); 
	}
}
@end 

调用方法(oc):

#import "UIApplication+LaunchScreen.h" 
[UIApplication.sharedApplication clearLaunchScreenCache];

猜你喜欢

转载自blog.csdn.net/m0_46728513/article/details/105633515