ios - 应用程序更新、NSURL 和文档目录

标签 ios nsurl updates nsdocumentdirectory

我在应用商店中有一个应用程序使用核心数据来保存大部分数据。 异常(exception)情况是存储图像。我将图像存储在 Documents 目录的子目录中,并将对该图像的 NSURL 引用存储在核心数据存储的适当对象属性中。

我们注意到,当更新进入应用商店时,这些图像找不到,因此不会显示,使用存储在以前版本的应用程序中的引用。 现在,我怀疑问题在于,由于我们正在使用开发设备进行测试,所以这个问题会传播,因为开发应用程序使用的应用程序目录中的目录与应用程序商店正在创建/使用的目录不同。我注意到应用程序中应用程序的应用程序商店目录与在 Xcode 中调试版本时创建的目录之间存在差异。 因此,存储在核心数据中的 URL 指向错误的应用程序文件夹。 这有点难以调试,因为一旦新版本在商店中发布,我就无法下载旧版本的应用程序。

所以我有几个问题。我能否保证下载同一应用程序版本的人们所在的应用程序子目录相同,从而使这对非开发设备来说不是问题?

我应该存储相对图像 url 或字符串来表示这些资源的位置,还是应该存储最终成为绝对 url 的内容?

非常感谢, 菲利普

最佳答案

您应该使用相对 URL 来存储对文件的引用。应用更新后,绝对 URL 可能会发生变化

Files Saved During App Updates

When a user downloads an app update, iTunes installs the update in a new app directory. It then moves the user’s data files from the old installation over to the new app 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.

https://developer.apple.com/library/ios/#DOCUMENTATION/iPhone/Conceptual/iPhoneOSProgrammingGuide/PerformanceTuning/PerformanceTuning.html

感谢沙盒,应用程序主页也是用户主页。所以可以使用 unix 代字号,它是用户主页的简写,即 ~/Documents~/Library 等等。

使用 -[NSString stringByAbbreviatingWithTildeInPath] 将完整路径转换为相对路径。并使用 -[NSString stringByExpandingTildeInPath] 反转它。

关于ios - 应用程序更新、NSURL 和文档目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9608971/

相关文章:

xcode - Swift 中的字符串问题

swift - 如何在 NSURL 中使用特殊字符?

swift - 从 UIImagePickerController 获取 NSURL

javascript - 在应用程序商店中发布后更新 Cordova 应用程序中的 javascript 代码

ios - 如何在 iOS 图表中设置最小 x 轴间隔?

ios - SwiftUI View 内容布局意外弹出/跳转出现?

objective-c - 如何向 UITextView 添加文本阴影?

iOS 蓝牙键盘未注册 VoiceOver control+option/(CTRL+ALT) 键同时按下

更新 macOS 后 Xcode 更新卡住

java - JSF 2.0 : data not updated before the view is rendered