有没有办法(通过编程)找到“Resource”文件夹的位置。我想在运行时在其中创建一个新文件。
获取资源文件夹路径的方法如下:
NSString *path = [[NSBundle mainBundle] resourcePath];
然而,在运行时您将无法在那里编写任何内容。新文件应保存到以下目录之一(取决于它们的用途):
Documents directory - persists between app launches and backuped by iTunes
NSString* docPath = [NSSearchPathForDirectoriesInDomains
(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
Caches directory - persists between app launches but not backuped by iTunes - you should place there files that can be easily restored by your program to improve device backup time
NSString* cachesPath = [NSSearchPathForDirectoriesInDomains
(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0];
Temporary directory - may not persist between app launches
NSString* tempPath = NSTemporaryDirectory();