你能在这行代码中找到一个bug吗?它返回nil!!该应用程序完全沙箱,但下载文件夹访问是启用的。
NSArray*array = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:[NSHomeDirectory() stringByAppendingPathComponent:@"/Downloads/"] error:NULL];
//array==nil: Why?编辑问题:我不能测试它。这发生在审查机器的来宾账户上。编译后的二进制文件会不会有什么问题,或者你有没有什么技巧可以解决这个问题?
发布于 2011-08-12 15:38:27
尝试使用错误句柄读取目录,以检查发生的情况:
NSError *error = nil;
NSArray*array = [[NSFileManager defaultManager]
contentsOfDirectoryAtPath:
[NSHomeDirectory() stringByAppendingPathComponent:@"/Downloads/"]
error:&error];
if ( !array )
NSLog(@"ERROR: %@", [error description]);这将为您提供更详细的错误描述。
要将此错误记录到文件中,请使用以下消息:
[[error description] writeToFile:@"strangeerrors.log"
atomically:NO encoding:NSUTF8StringEncoding error:nil];发布于 2011-08-17 02:42:42
你有没有试过更换
[NSHomeDirectory() stringByAppendingPathComponent:@"/Downloads/"]使用
[@"~/Downloads" stringByExpandingTildeInPath]发布于 2011-09-21 20:54:08
在附加路径组件时,您不需要放入任何斜杠。这很简单:
[NSHomeDirectory() stringByAppendingPathComponent:@"Downloads"] ...对我来说很好!
https://stackoverflow.com/questions/7036909
复制相似问题