NSFileManager 错误?
你能发现这行代码中的错误吗?它返回零! 该应用程序完全沙盒化,但启用了下载文件夹访问。
NSArray*array = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:[NSHomeDirectory() stringByAppendingPathComponent:@"/Downloads/"] error:NULL];
//array==nil: Why?
[编辑]问题:我无法测试它。它发生在评论机器的来宾帐户上。编译的二进制文件是否有问题,或者您有任何解决此问题的提示吗?
Can you find a bug in this line of code? It returns nil!!
The app is completely sandboxed but Downloads folder access is enabled.
NSArray*array = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:[NSHomeDirectory() stringByAppendingPathComponent:@"/Downloads/"] error:NULL];
//array==nil: Why?
[EDIT] Problem: I cannot test it. It is happening on a Guest account of the review machines. Could there be something wrong with the complied binary or have you got any tips how to solve this issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
尝试读取带有错误句柄的目录来检查发生了什么:
这将为您提供更详细的描述出了什么问题。
要将此错误记录到文件quick'n'dirty,请使用以下消息:
Try to read the directory with an error handle to examine what happens:
That will give you a more detailed description what went wrong.
To log this error to a file quick'n'dirty use the following message:
您是否尝试过替换
为
?
Have you tried replacing
with
?
附加路径组件时不需要添加任何斜线。很简单:
对我来说效果很好!
You don't need to put in any slashed when appending path components. It's simply:
Works fine for me!
几乎可以肯定这不是真正的问题,但可以说将
@"Downloads/"
附加为路径组件比使用前导斜杠更有意义。在 Cocoa 看来,请求@"/Downloads/"
的组件将为您提供:这可能不是您想要的。
Almost certainly not the real problem here, but arguably it makes more sense to append
@"Downloads/"
as a path component, rather than with a leading slash. In Cocoa's eyes, asking for the components of@"/Downloads/"
will give you:which is probably not what you intended.