如何清除 iOS APP 的启动屏幕缓存

移动开发 iOS
我在应用程序的沙盒中进行了一些挖掘,发现该 Library 文件夹中有一个名为 SplashBoard 的文件夹,该文件夹是启动屏缓存的存储位置。

[[407817]]

本文转载自微信公众号「网罗开发」,作者韦弦Zhy 。转载本文请联系网罗开发公众号。

简介

每当我在我的 iOS 应用程序中修改了 LaunchScreen.storyboad 中的某些内容时,我都会遇到一个问题:

系统会缓存启动图像,即使删除了该应用程序,它实际上也很难清除原来的缓存。

有时我修改了 LaunchScreen.storyboad,删除应用程序并重新启动,它显示了新的 LaunchScreen.storyboad,但 LaunchScreen.storyboad 中引用的任何图片都不会显示,从而使启动屏显得不正常。

今天,我在应用程序的沙盒中进行了一些挖掘,发现该 Library 文件夹中有一个名为 SplashBoard 的文件夹,该文件夹是启动屏缓存的存储位置。

因此,要完全清除应用程序的启动屏幕缓存,您所需要做的就是在应用程序内部运行以下代码(已将该代码扩展到 UIApplication 的中):

  1. import UIKit 
  2.  
  3. public extension  UIApplication { 
  4.  
  5.     func clearLaunchScreenCache() { 
  6.         do { 
  7.             try FileManager.default.removeItem(atPath: NSHomeDirectory()+"/Library/SplashBoard"
  8.         } catch { 
  9.             print("Failed to delete launch screen cache: \(error)"
  10.         } 
  11.     } 
  12.  

在启动屏开发过程中,您可以将其放在应用程序初始化代码中,然后在不修改启动屏时将其禁用。

这个技巧在启动屏出问题时为我节省了很多时间,希望也能为您节省一些时间。

使用

  1. UIApplication.shared.clearLaunchScreenCache() 
  • 文章提到的缓存目录在沙盒下如下图所示:

  • OC 代码,创建一个 UIApplication 的 Category
  1. #import <UIKit/UIKit.h> 
  2.  
  3. @interface UIApplication (LaunchScreen) 
  4. - (void)clearLaunchScreenCache; 
  5. @end 
  6. #import "UIApplication+LaunchScreen.h" 
  7.  
  8. @implementation UIApplication (LaunchScreen) 
  9. - (void)clearLaunchScreenCache { 
  10.     NSError *error; 
  11.     [NSFileManager.defaultManager removeItemAtPath:[NSString stringWithFormat:@"%@/Library/SplashBoard",NSHomeDirectory()] error:&error]; 
  12.     if (error) { 
  13.         NSLog(@"Failed to delete launch screen cache: %@",error); 
  14.     } 
  15. @end 

OC使用方法

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

 

责任编辑:武晓燕 来源: 网罗开发
相关推荐

2019-07-26 15:10:49

Windows 10屏幕缓存Windows

2021-11-23 10:25:35

性能优化iOS App 启动优化

2017-10-12 11:25:01

ChromeDNS缓存

2020-11-24 19:20:02

iOS夜间模式缓存

2020-11-09 16:35:42

UbuntuLinux发行版

2020-11-04 18:32:30

APTapt命令Linux

2020-10-27 11:00:57

LinuxRAM缓存

2012-01-05 09:19:25

iOSApp应用

2009-12-16 10:20:17

服务器DNS缓存

2018-12-07 12:54:22

App美团外卖iOS客户端

2011-06-01 09:03:12

Android 缓存

2020-10-19 07:26:23

APP启动面试官

2023-11-02 09:42:21

iOS屏幕旋转

2018-03-12 10:30:14

APP清除缓存数据

2015-12-30 15:36:53

Windows清除缓存

2013-07-03 15:11:41

ANdroid

2013-05-17 10:19:17

2014-09-17 11:45:20

iOS编程App运作

2017-11-10 13:02:44

iOSUI代码

2015-02-28 09:49:22

lua
点赞
收藏

51CTO技术栈公众号