Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在iOS上查找文档目录的替代方法_Ios - Fatal编程技术网

在iOS上查找文档目录的替代方法

在iOS上查找文档目录的替代方法,ios,Ios,通常,在iOS上查找文档目录的答案包括以下代码: + (NSString *) applicationDocumentsDirectory { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:

通常,在iOS上查找文档目录的答案包括以下代码:

+ (NSString *) applicationDocumentsDirectory 
{    
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
    return basePath;
}
但是,我发现了另一个版本:

+ (NSString *)applicationDocumentsDirectory
{
    return [@"~/Documents" stringByExpandingTildeInPath];
}
有什么理由我不能用这个吗?也许文档目录将来可能不在主目录中?

这怎么办

NSString *resourcePath = [[NSBundle mainBundle] resourcePath];
有什么理由我不能用这个吗?也许文档目录将来可能不在主目录中

我想你在这里回答了你自己的问题

第一种方法询问操作系统文档目录的位置,并且不假设任何内容


第二种方法假定Documents目录的位置。

因为这样就不能得到Documents目录?