NSSearchPathForDirectoriesInDomains返回错误的目录 [英] NSSearchPathForDirectoriesInDomains returns the wrong directory

查看:532
本文介绍了NSSearchPathForDirectoriesInDomains返回错误的目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES)在我的应用程序中获取应用程序文档目录,但返回的数组只包含一个对象,不可写的不正确目录:

I'm using NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) to get the application documents directory in my app, but the array that's returned contains only one object, and it's an unwritable, incorrect directory:

/ Users / me / Library / Application Support / iPhone Simulator / Documents

/Users/me/Library/Application Support/iPhone Simulator/Documents

我发现此问题表示问题与配置相关,但答案说比那更多。所以我想我提出一个重复的问题,但这个问题的答案是不够的,所以我希望得到一个实际的答案在这一个。

I found this question which indicates that the problem is related to provisioning, but the answer says little more than that. So I guess I'm asking a duplicate question, but the answer to that question is insufficient, so I'm hoping to get an actual answer in this one.

推荐答案

嗯...所以一个原因,返回的目录可能不同,你期望的应用程序可能与Xcode目标类型相关。这不会发生是一个测试目标吗?在这种情况下,正确的答案很可能是一个应用程序GUID的答案,因为事实上它不是一个应用程序。此 google小组讨论意味着,如果是这种情况,您会是好的只需创建目录。

Hmm ... so one reason that the directory returned might be different that what you'd expect for an app could be related to the Xcode target type. This wouldn't happen to be a testing target would it? in which case the correct answer could well be an answer w/o an application GUID in it, since in fact it's not an application. This google group discussion implies that if this is the case, you'd be good with simply creating the directory.

只是为了咧嘴,我从终端窗口创建了目录/ Users / me / Library / Application Support / iPhone Simulator / Documents它似乎运行。仍然有测试错误,但这些可能是真实的。

Just for grins, I created the directory /Users/me/Library/Application Support/iPhone Simulator/Documents from the terminal window, and now it appears to run. There are still test errors, but those might be real.

我建议您更改您的测试应用程序创建文档目录,如果它缺少 - 类似: / p>

I'd recommend that you change your test app to create the documents directory if it's missing - something like:

  if(![[NSFileManager defaultManager] createDirectoryAtPath:NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) withIntermediateDirectories:YES attributes:nil error:NULL])
        NSLog(@"Error: Create folder failed %@", NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES));

这篇关于NSSearchPathForDirectoriesInDomains返回错误的目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆