Issue with NSSearchPathForDirectoriesInDomains And Persistent Data

▼魔方 西西 提交于 2020-01-13 05:43:09

问题


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];

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.

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.


回答1:


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.

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

In other words, don't save PATHS such as

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

Instead save:

/MyDirectory/MyFile.txt

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



来源:https://stackoverflow.com/questions/6007494/issue-with-nssearchpathfordirectoriesindomains-and-persistent-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!