I have an app where I recently replaced the launch images and app icons, I removed all of the old assets from everywhere in the project. When I upgrade the app from the old version to the new version by just building in Xcode, everything is fine. However, if I have the old version of my app installed then upgrade it from TestFlight, every time I kill the app then restart it the old launch image briefly appears before showing the new launch image. Similarly when I then close the app, the old app icon briefly flashes before switching back to my new one.

我使用iExplorer打开应用,并注意到/Library/Caches/Shapshots目录中保存了旧的启动屏幕图像(我不知道它是如何或为什么会出现在那里)。当我通过iExplorer手动删除它时,它就不再出现了。但是,当我尝试使用NSFileManager方法用代码删除它时,我得到错误,说我被禁止删除这个目录中的文件。

有人有过这样的经历吗?有什么建议吗?


当前回答

尝试打开模拟器,进入硬件->擦除所有内容和设置。

其他回答

也有这个问题。作为一个新手,我很天真地改变了启动屏幕。故事板到LaunchScreen.xib。运行失败了(呸),所以我把它改回。storyboard重新运行了应用程序,只是为了测试我没有搞砸任何其他事情——旧的屏幕没有首先出现。所以不管我做了什么,它一定把旧缓存冲出来了。

首先

清洁与建造项目

方法1: 重命名LaunchScreen.storyboard中加载的Splash图像。

例如,我加载了“splash”,但将其更改为“splashNew”。

方法2:

在不同的设备或模拟器上运行应用程序

例如,如果你在模拟器iphone 11中运行应用程序,那么将它运行到iphone 12中

使用这段代码清理启动屏幕缓存:

import UIKit

public extension UIApplication {
    func clearLaunchScreenCache() {
        #if DEBUG
        do {
            let launchScreenPath = "\(NSHomeDirectory())/Library/SplashBoard"
            try FileManager.default.removeItem(atPath: launchScreenPath)
        } catch {
            print("Failed to delete launch screen cache - \(error)")
        }
        #endif
    }
}

用法:

UIApplication.shared.clearLaunchScreenCache()

有同样的问题,但只是在启动屏幕故事板使用的图像。将图像从资产目录中移动,并将其名称更改为应用程序包(例如,资产目录中设置的旧图像称为launch_logo,应用程序包中的图像称为launchscreen_logo.png)解决了我们的问题。

我找到了变通方案,如果你真的想解决这个问题。 苹果公司有一些机制来缓存启动屏幕的图像,通过图像文件名进行索引。

当你改变任何图像在启动屏幕上,你想看到这些变化在下次运行立即。请使用你修改过的新图片名称,并链接到storyboard或xib中的新图片文件。

再次运行,您将看到新的更改出现。