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
我正在使用Objective-C为iOS编程什么是保存我下载的mp3文件的最佳位置(我的意思是路径或本地URL),我使用我的代码下载了什么,以及保存包含有关信息的Plist文件的最佳位置下载歌曲
2 个解决方案
#1
4
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:
由于iOS(和应用程序沙盒)的性质,您只能保存在应用程序的文档目录中。要获取此目录的路径,您可以使用:
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.
我建议阅读文件系统编程指南,因为它涵盖了这个主题(还有更多),包括iCloud文件管理等。
#2
2
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:
对于tmp目录:
NSString *tmpDirectory = NSTemporaryDirectory();
#1
4
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:
由于iOS(和应用程序沙盒)的性质,您只能保存在应用程序的文档目录中。要获取此目录的路径,您可以使用:
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.
我建议阅读文件系统编程指南,因为它涵盖了这个主题(还有更多),包括iCloud文件管理等。
#2
2
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:
对于tmp目录:
NSString *tmpDirectory = NSTemporaryDirectory();