Reputation: 1207
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
Upvotes: 0
Views: 1831
Reputation: 1858
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();
Upvotes: 3
Reputation: 54445
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.
Upvotes: 4