寻找资源文件夹的路径?

4

有没有办法(通过编程)找到“Resource”文件夹的位置。我想在运行时在其中创建一个新文件。

1个回答

8

获取资源文件夹路径的方法如下:

NSString *path = [[NSBundle mainBundle] resourcePath];

然而,在运行时您将无法在那里编写任何内容。新文件应保存到以下目录之一(取决于它们的用途):

  1. Documents directory - persists between app launches and backuped by iTunes

    NSString* docPath = [NSSearchPathForDirectoriesInDomains
                   (NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    
  2. 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];
    
  3. Temporary directory - may not persist between app launches

    NSString* tempPath = NSTemporaryDirectory();
    

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接