Every time I’ve had to change something in the launch screen on any of my iOS apps, I’ve faced an issue: the system caches launch images and is really bad at clearing said cache, even after the app has been deleted.

Sometimes I’d change the launch screen storyboard, delete the app and re-launch, and it would show the new storyboard, but any images referenced in the storyboard wouldn’t show up, making the launch screen appear broken.

Today, I did some digging into my app’s container and noticed that in the Library folder there’s a folder named SplashBoard, which is where the launch screen caches are stored.

So all you have to do to completely clear your app’s launch screen cache is run this code inside your app (which I’ve conveniently packaged into an extension of 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)")
       }
    }
}

Note: tested on iOS 13 only

You can put it in your app’s initialization code behind an argument flag that you enable during launch screen development, then leave it disabled when you’re not working on your launch screen.

This trick has saved me a lot of time while messing with launch screens, and I hope it will save you some time as well.


原文链接:https://rambo.codes/ios/quick-tip/2019/12/09/clearing-your-apps-launch-screen-cache-on-ios.html

你可能感兴趣的文章

评论区

发表评论

必填

选填

选填

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。