为什么NSCachesDirectory只读?

时间:2015-05-13 07:59:37

标签: ios objective-c iphone

NSCachesDirectory是否可能只在设备上读取?我的应用程序的一些用户报告了一些错误,我将其指向此

NSString *path = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
path = [path stringByAppendingPathComponent:@"VideoCache"];

NSError *error = nil;
[[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:&error];

if (error) {
    NSLog(@"Error while trying to create directory at path %@: %@", path, error.description);
    path = nil;
}

NSString *filePath = [path stringByAppendingPathComponent:@"config.json"];

NSDictionary * json = @{ @"foo" : @"bar"};
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:json options:NSJSONWritingPrettyPrinted error:&error];

[jsonData writeToFile:filePath options:NSDataWritingAtomic error:&error];

writeToFile崩溃,因为path为零。在caches文件夹中创建目录时,createDirectoryAtPath在哪些情况下会返回错误?我设法在模拟器上重现它的唯一方法是将应用程序的缓存文件夹设置为只读。

感谢

0 个答案:

没有答案