我正在文档文件夹中创建目录。它适用于较低版本的ios,即ios 6,7到8.0。
但它在ios 8.1.3中产生了问题。
NSString *folderPath;
NSArray *path = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
NSString *library = [path objectAtIndex:0];
folderPath = [library stringByAppendingPathComponent:@"Documents/custom"];
BOOL success = [[NSFileManager defaultManager] createDirectoryAtPath:folderPath withIntermediateDirectories:NO attributes:nil error:nil];
NSLog(@"create %d",success);
对于ios版本8.1.3,创建返回0。
任何人都可以提出正在发生的事情。
答案 0 :(得分:0)
错误==
2015-02-02 17:37:10.561 ALLDOX [903:51379]创建错误域= NSCocoaErrorDomain Code = 4"操作无法完成。 (可可错误4。)" UserInfo = 0x1565f500 {NSFilePath = / var / mobile / Containers / Data / Application / 36F75DC4-C5E1-4501-A13D-0B17A3B2663E / Library / Documents / custom,NSUnderlyingError = 0x1565d7b0"操作无法完成。没有这样的文件或目录"}
我得到了答案
Apple更改了目录路径。
/var/mobile/Containers/Data/Application/36F75DC4-C5E1-4501-A13D-0B17A3B2663E/Library/Documents/custom //Wrong path in ios 8.1.*
/var/mobile/Containers/Data/Application/36F75DC4-C5E1-4501-A13D-0B17A3B2663E/Documents/custom //Correct path for ios 8.1.*
获取正确目录的正确代码是
NSString *folderPath;
folderPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/custom"];
BOOL success = [[NSFileManager defaultManager] createDirectoryAtPath:folderPath withIntermediateDirectories:NO attributes:nil error:nil];
NSLog(@"create %d",success);
参见参考link