iOS Application Library directory <uid> always gets changed

血红的双手。 提交于 2019-12-07 22:26:07

问题


After reading Apple documentation, I used URLsForDirectory to obtain the Library destination within my app, and my objective is to download content from a hosted service & cache it in the Library folder, so that User cannot interact with the contents through iTunes. NSArray *docPaths= [[NSFileManager defaultManager] URLsForDirectory:NSLibraryDirectory inDomains:NSUserDomainMask]; NSLog(@"%@",[docPaths description]); NSString *docPath=[(NSURL *)[docPaths objectAtIndex:0] path]; docPath = [docPath stringByAppendingPathComponent:@"audios"];

Running & executing the code several times(various simulators, and iOS 8.0 device) I realized that somehow the content being fetched seems to be no longer accessible, so I logged the library destination path, and after running app every time the destination path seems to have changed:

/var/mobile/Containers/Data/Application/83725F33-C7EA-4F89-B69F-0AECF26FA77A/Library/"

/var/mobile/Containers/Data/Application/4627FC86-C3A4-4A1A-9721-AF73D808433E/Library/"

/var/mobile/Containers/Data/Application/709CCA84-936A-4596-933A-D6779758FF85/Library/

Has anybody faced a similar issue? If so how did it got corrected? And is there anything I've missed out here?


回答1:


I had the same issue. I think the variable part changes only when the code is recompiled (ie not if you just rerun without making changes), so should not affect a live app. But I decided in the end not to save the path - just to use the same code (as you use above) both when saving and retrieving the data. It seems to work, in spite of the fact that the path actually changes between runs (so the simulator must copy the files across, or rename the folder).



来源:https://stackoverflow.com/questions/26552245/ios-application-library-directory-uid-always-gets-changed

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