简体   繁体   中英

where is best place to save application files in IOS

I am programming for iOS using Objective-C
what is the best place (I mean path or local URL ) to save my downloaded mp3 files that I download using my code and what is the best place to save the Plist file that contains information about the downloaded songs

Due to the nature of iOS (and app sandboxing), you can only save within your app's document directory. To obtain the path to this directory, you can use:

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

One advantage of the sandbox approach is the fact that when your app is updated on the device, the files in the document directory will remain untouched and hence can be updated by the app as required.

I'd recommend a read of the File System Programming Guide , as it covers this topic (and a lot more), including iCloud file management, etc.

For Document Directory:

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

For Caches Directory:

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

For tmp Directory:

NSString *tmpDirectory = NSTemporaryDirectory();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM