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方法用代码删除它时,我得到错误,说我被禁止删除这个目录中的文件。

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


当前回答

在AppDelegate中试试

    if #available(iOS 13.0, *) {
        do {
            try FileManager.default.removeItem(atPath: NSHomeDirectory()+"/Library/SplashBoard")
        } catch {
            print("Failed to delete launch screen cache: \(error)")
        }
    } else {
        print("ios is min")
    }

其他回答

Springboard使用这些缓存来快速切换应用程序。这个问题不会影响到你的产品用户,理论上,下次Springboard决定对你的应用进行快照时,这个问题就会消失。

也就是说,这不是一个你能解决的问题。这是苹果代码中的bug,不是你的。

更新: 似乎有一个不需要重新启动设备的解决方案。

这将在第二次发射后生效!

do {
   try FileManager.default.removeItem(atPath: NSHomeDirectory()+"/Library/SplashBoard")
} catch {
   print("Failed to delete launch screen cache: \(error)")
}

关于它是如何工作的完整解释:https://www.rambo.codes/posts/2019-12-09-clearing-your-apps-launch-screen-cache-on-ios

这是我发现的解决这个问题的最快方法,尽管听起来很愚蠢:

右键单击LaunchScreen。xibor在你的启动屏幕文件,并选择删除文件,然后选择删除垃圾。这将从项目中删除对该文件及其过去更新的所有引用。 进入你的垃圾和拖放文件回到你的xCode项目(在yourProjectName)。 清理和重建。

对我有用的是:

删除启动屏幕的场景和视图控制器,并创建一个新的(确保你在属性检查器中将其设置为“初始视图控制器”)。

什么对我不起作用:

删除应用 重新启动iPhone、Mac或Xcode 删除派生数据 删除设备的容器 清洁 焚烧3个史蒂夫·乔布斯的巫毒娃娃

注意:

有时也需要擦除(模拟器)

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

我想这要视情况而定。 当它发生在调试或测试时,在启动屏幕上删除图像。 或者卸载你的应用程序,然后重新启动。

但它在存档之后仍然存在,它不能通过重置和清理来解决。