gpt4 book ai didi

iphone - /Library/Caches 在应用程序更新时会清晰吗?

转载 作者:行者123 更新时间:2023-12-03 18:17:41 29 4
gpt4 key购买 nike

在我的 iPhone 应用程序中,我缓存了一些压缩文件的原始数据以节省加载时间。但这些文件可能会在更新中更改。

当应用程序更新时,iOS 会为我清除/Library/Caches 还是我需要自己清除它?

最佳答案

简短:

应用程序更新时,iOS 会为我清除/Library/Caches

iOS 是否有可能在更新期间清除 Application_Home/Library/Caches 的所有内容或部分内容?

或者我需要自己清除它?您需要确保您想要清除的内容已被清除。

为这两种情况做好准备。

您如何知道您的应用是否已更新?请参阅iOS Application Update Test

长:

Files Saved During Application Updates When a user downloads an application update, iTunes installs the update in a new application directory. It then moves the user’s data files from the old installation over to the new application directory before deleting the old installation. Files in the following directories are guaranteed to be preserved during the update process:

  • Application_Home/Documents
  • Application_Home/Library

Although files in other user directories may also be moved over, you should not rely on them being present after an update.

来自苹果文档:The Application Runtime Environment - Backup and Restore

Application_Home/Library/Caches Use this directory to write any application-specific support files that you want to persist between launches of the application or during application updates. Your application is generally responsible for adding and removing these files. It should also be able to re-create these files as needed because iTunes removes them during a full restoration of the device. In iOS 2.2 and later, the contents of this directory are not backed up by iTunes.

来自苹果文档:The Application Runtime Environment - The File System (daveon代码)

以下是在“更新”期间清除缓存的示例:您安装应用程序 X V1.0。吃完午饭就开始做别的事。 iOS 出现故障,需要恢复。开发者发布V1.1。您可以在 Mac 上的 iTunes 中更新应用程序。您可以通过 iTunes 恢复您的设备。 iTunes 安装 V1.1。用户为您的应用程序提供午餐。您的应用不会收到发生任何此类情况的通知,但 Application_Home/Library/Cache 中的所有文件都消失了(iTunes 会在设备完全恢复期间删除它们)。

其中非常重要的信息:它还应该能够根据需要重新创建这些文件。就像肯德尔也指出的那样,它是一个缓存,因此操作系统可以随时从其中删除文件。因此,每次从 Application_Home/Library/Caches 加载任何文件时,您都必须考虑该文件不再存在的情况(Kendall 谈到了这一点)。

NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *cachePath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0];
if(![fileManager fileExistsAtPath:[cachePath stringByAppendingPathComponent:@"myfile.zip"]]) {
//create it, copy it from app bundle, download it etc.
}
//start using it

关于iphone - <Application_Home>/Library/Caches 在应用程序更新时会清晰吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7155964/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com