NSSearchPathForDirectoriesInDomains和永久数据的问题 [英] Issue with NSSearchPathForDirectoriesInDomains And Persistent Data

查看:139
本文介绍了NSSearchPathForDirectoriesInDomains和永久数据的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据建议,我们正在使用以下代码来检索用户文档的路径

As suggested, we're using the following code to retrieve the user document's path

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];

作为结果,我们得到以下路径:/var/mobile/Applications/3E3C1F45-6649-4EA3-93FD-CDB802E346EC/Documents/

we get the following path as as result: /var/mobile/Applications/3E3C1F45-6649-4EA3-93FD-CDB802E346EC/Documents/

在上述路径中,我们保存了所有用户的持久数据.

In said path, we save all the user's persistent data.

我们从应用程序商店升级了应用程序版本的用户遇到了一些问题,不再需要读取持久数据,也许更改了路径,也许在新版本中使用了新的GUID.

We encountered some problem with users who upgraded the application's version from the app-store, the persistent data is no longed read, perhaps the path is changed, maybe a new GUID is used within the new version.

由于这种情况仅在应用商店更新后才会发生,因此测试和调试此问题的能力有限.

Since this happens only after an appstore update, with a limitied ability to test and debug this issue.

推荐答案

用户升级应用程序时,标识符(3E3C1F45-6649-4EA3-93FD-CDB802E346EC)可以更改,但文档和缓存应复制到新的目录从旧的.

When the user upgrades the App, the identifier (3E3C1F45-6649-4EA3-93FD-CDB802E346EC) can change but the documents and caches should be copied to the new directory from the old one.

是否有可能将绝对路径保存到持久数据中并在加载文件时尝试使用它?您应该只将文件名和目录名保存在documents目录中,并在每次加载资源时(或至少在启动时)通过附加NSSearchPathForDirectoriesInDomain返回的路径来生成完整路径

Is there any chance that you are saving the ABSOLUTE path to your persistent data and trying to use it when loading files? You should be saving only the filenames and directory names within the documents directory, and generating the full path every time you load a resource (or at least at startup) by appending the path returned by NSSearchPathForDirectoriesInDomain

换句话说,不要保存

/var/mobile/Applications/3E3C1F45-6649-4EA3-93FD-CDB802E346EC/Documents/MyDirectory/MyFile.txt

/var/mobile/Applications/3E3C1F45-6649-4EA3-93FD-CDB802E346EC/Documents/MyDirectory/MyFile.txt

代替保存:

/MyDirectory/MyFile.txt

/MyDirectory/MyFile.txt

,并将其附加到运行时NSSearchPathForDirectoriesInDomain返回的任何内容.

and append it to whatever is returned by NSSearchPathForDirectoriesInDomain at runtime.

这篇关于NSSearchPathForDirectoriesInDomains和永久数据的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆