是iPhone应用程序的文档目录/ var / mobile / Documents或/ var / mobile / Library / AppName? [英] Is an iPhone app's document directory /var/mobile/Documents or /var/mobile/Library/AppName?

查看:294
本文介绍了是iPhone应用程序的文档目录/ var / mobile / Documents或/ var / mobile / Library / AppName?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知(并且无处不在),应用程序的文档目录应该在iPhone上的 / var / mobile / Library / 中,但如果我正在记录得到的目录是 / var / mobile / Documents



我得到的目录如下:

  NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES); 
NSString * documentsDirectory = [paths objectAtIndex:0];

这是一个问题,如果我创建一个名为 Settings.xml 在这里或者是我的应用程序/ etc有问题?



信息:我有一个越狱iPhone 4与iOS 4.2.1和我的应用程序通过Cydia或SSH安装。






更新 b

是的,但那个目录和我的应用程序没有真正的关系。
例如,我创建一个文档settings.xml,如果另一个应用程序使用相同的NSDocumentDirectory和相同的文件名,如何?
是的,我知道。 Cydia应用程序安装到/应用程序,但应该有一个文档目录为我的应用程序,甚至不是/ var / mobile / Documents。如果您查看 http://thebigboss.org / hosting / repository / submit-your-app / compile-for-cydia-submission 目录应该是/ var / mobile / Library /但是如前所述,我从来没有得到这个目录。

解决方案

使用常量 NSDocumentDirectory 会在运行时得到/ var / mobile /越狱应用程序。将应用程序的文档直接转储到其中是一种糟糕的政策,即使您认为它们的名称是唯一的。



如果您查看/ var / mobile / Library /文件夹的内容,您会看到许多应用程序的数据存储在那里,包括越狱应用程序。我不清楚是否有一个方便的常量像 NSDocumentDirectory ,你可以使用来获得它。但是,您可以始终硬编码您的源代码以查找 @/ var / mobile / Library / APPNAME中的文件。这个文件夹不太可能改变(如果是这样,它可能会打破其他应用程序,这当然是一个容易解决的问题)。



如果你看文档链接到,确定指定:


Appstore应用程序具有由
安装过程创建的文档文件夹。越狱应用程序不。它是由应用程序到
创建自己的文件夹。如果你需要这种类型的文件夹,你必须
在你的
applicationDidFinishLaunching函数中用一个简单的mkdir命令创建它。只需添加一个简单的函数:
mkdir(/ var / mobile / Library / YOURAPPNAME,0755);如果文件夹已经有
存在,则不会造成危害。您想这样做,因为安装过程
作为root用户运行,应用程序作为用户移动运行。如果Cydia为你这个
,那么该文件夹的权限不正确。


... 需要自己创建该子目录



根据我的经验,编写越狱应用程序只涉及一些稍微臭的编码实践(硬编码路径并自己创建它们) )...它可能只是我们必须处理的。



更新:请务必在下面看到Saurik的注释。 >

As far as I know (and read everywhere) an application's documents directory should be somewhere in /var/mobile/Library/ on the iPhone but if I'm logging the gotten directory it is /var/mobile/Documents.

I get the directory as follows:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];

is this a problem if I'm creating a file named Settings.xml in here or is something wrong with my app/etc.?

Information: I've a jailbroken iPhone 4 with iOS 4.2.1 and my app gets installed via Cydia or SSH.


Update

Yeah, but that directory is not really related to my application. For example I am creating a document settings.xml and what if another application uses the same NSDocumentDirectory and the same file name? And yes, I know. Cydia apps got installed into /Applications but there should be a document directory for my app too and not even /var/mobile/Documents. If you take a look at http://thebigboss.org/hosting-repository/submit-your-app/compile-for-cydia-submission the directory should be /var/mobile/Library/ but as I described before, I never get this directory.

解决方案

Using the constant NSDocumentDirectory will in fact get you /var/mobile/Documents when running a jailbreak app. It would be bad policy to dump your app's documents directly in there, even if you think they're named uniquely.

If you look at the contents of the /var/mobile/Library/ folder, you'll see that many apps have their data stored there, including jailbreak apps. It's not clear to me whether there's a handy constant like NSDocumentDirectory that you can use to get that. But, you can always hardcode your source to look for files in @"/var/mobile/Library/APPNAME". It's unlikely that this folder will change (and if it does, it's probably going to break other apps, and is certainly an easy fix to make).

If you look at the document you link to, it does specify:

Appstore app has a Documents folder that is created by the installation process. Jailbroken app does not. It is up to the app to create its own folder. Should you need this type of folder, you must create this with a simple mkdir command in your applicationDidFinishLaunching function. Just add a simple function: mkdir("/var/mobile/Library/YOURAPPNAME", 0755); If the folder already exists, no harm done. You want to do this because the install process runs as user root and the app runs as user mobile. If Cydia does this for you then the folder will have the incorrect permissions.

... so you need to create that subdirectory yourself. It won't be there if you don't.

In my experience, writing jailbreak apps simply involves some of these slightly stinky coding practices (hardcoding paths and creating them ourselves) ... it might just be something we have to deal with.

Update: make sure to see Saurik's comment below.

这篇关于是iPhone应用程序的文档目录/ var / mobile / Documents或/ var / mobile / Library / AppName?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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