本文转载自微信公众号「网罗开发」,何清缓存作者韦弦Zhy 。启动转载本文请联系网罗开发公众号。屏幕
每当我在我的何清缓存 iOS 应用程序中修改了 LaunchScreen.storyboad 中的某些内容时,我都会遇到一个问题:
系统会缓存启动图像,启动即使删除了该应用程序,屏幕它实际上也很难清除原来的何清缓存缓存。
有时我修改了 LaunchScreen.storyboad,启动删除应用程序并重新启动,屏幕它显示了新的何清缓存 LaunchScreen.storyboad,但 LaunchScreen.storyboad 中引用的启动任何图片都不会显示,从而使启动屏显得不正常。屏幕
今天,我在应用程序的沙盒中进行了一些挖掘,发现该 Library 文件夹中有一个名为 SplashBoard 的文件夹,该文件夹是启动屏缓存的存储位置。
因此,要完全清除应用程序的启动屏幕缓存,您所需要做的就是在应用程序内部运行以下代码(已将该代码扩展到 UIApplication 的中):
- import UIKit
- public extension UIApplication {
- func clearLaunchScreenCache() {
- do {
- try FileManager.default.removeItem(atPath: NSHomeDirectory()+"/Library/SplashBoard")
- } catch {
- print("Failed to delete launch screen cache: \(error)")
- }
- }
- }
在启动屏开发过程中,您可以将其放在应用程序初始化代码中,然后在不修改启动屏时将其禁用。
这个技巧在启动屏出问题时为我节省了很多时间,希望也能为您节省一些时间。
- UIApplication.shared.clearLaunchScreenCache()
- #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/SplashBoard",NSHomeDirectory()] error:&error];
- if (error) {
- NSLog(@"Failed to delete launch screen cache: %@",error);
- }
- }
- @end
OC使用方法
- #import "UIApplication+LaunchScreen.h"
- [UIApplication.sharedApplication clearLaunchScreenCache];
责任编辑:武晓燕 来源: 网罗开发 iOSAPP缓存
(责任编辑:综合)
富瀚微(300613.SZ)公布消息:就收购眸芯科技32.43%股权已完成工商变更登记
策划游戏《纪元1800》玩家数量突破250万 主机版3月16日上线
中青旅(600138.SH):2020年度由盈转亏 基本每股亏损0.3206元
明基EX480UZ显示器上市:48英寸OLED 4K120Hz