每當我在我的iOS應用程序中修改了LaunchScreen.storyboad
中的某些內容時原探,我都會遇到一個問題:
系統(tǒng)會緩存啟動圖像,即使刪除了該應用程序,它實際上也很難清除原來的緩存咽弦。
有時我修改了LaunchScreen.storyboad
徒蟆,刪除應用程序并重新啟動,它顯示了新的LaunchScreen.storyboad
型型,但LaunchScreen.storyboad
中引用的任何圖片都不會顯示段审,從而使啟動屏顯得不正常。
今天输莺,我在應用程序的沙盒中進行了一些挖掘戚哎,發(fā)現(xiàn)該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)")
}
}
}
在啟動屏開發(fā)過程中嘱函,您可以將其放在應用程序初始化代碼中甘畅,然后在不修改啟動屏時將其禁用。
這個技巧在啟動屏出問題時為我節(jié)省了很多時間往弓,希望也能為您節(jié)省一些時間疏唾。
使用:
UIApplication.shared.clearLaunchScreenCache()
以上內容來自Quick tip: clearing your app’s launch screen cache on iOS 簡單翻譯一下搬運過來,希望有用
附:
-
文章提到的緩存目錄在沙盒下如下圖所示:
app啟動圖緩存.png - OC代碼,創(chuàng)建一個
UIApplication
的 Category
#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];
同時有一篇文章有更詳細的方案:見 https://blog.csdn.net/olsQ93038o99S/article/details/108924170
賞我一個贊吧~~~