Issue with NSSearchPathForDirectoriesInDomains And

2019-04-13 04: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条回答
我想做一个坏孩纸
2楼-- · 2019-04-13 04:54

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.

查看更多
登录 后发表回答