为什么我会得到“Cocoa error 513”将文件写入“/ var / mydir / files”时在越狱的iPhone上? [英] Why do I get "Cocoa error 513" when write files to "/var/mydir/files" on an jailbroken iPhone?

查看:278
本文介绍了为什么我会得到“Cocoa error 513”将文件写入“/ var / mydir / files”时在越狱的iPhone上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序会将一些文件写入文件系统并将其安装在/ Application而不是/ var / mobile / Application中,在我的开发iPhone上,一切顺利。但是当分发给其他人时,他们得到了Cocoa error 513 。文件写在/ var / mydir / files,那有什么问题?在完全允许的情况下,我可以在哪里找到合适的地方?
谢谢。

My app will write some files to file system and it is installed in /Application not in /var/mobile/Application, On my develop iPhone, every things goes right.But when distribute to others, They got "Cocoa error 513".The files are written at /var/mydir/files, What's that problem? Where is right place for me to write with full permission? Thank you.

代码:

NSString *dir = @"/var/mydir/docs/";
NSFileManager *fileManager = [NSFileManager defaultManager];
if(![fileManager fileExistsAtPath:dir]) {
    NSError *error = nil;
    BOOL createdDir = [fileManager createDirectoryAtPath:dir withIntermediateDirectories:YES attributes:nil error:&error];
    if (!createdDir) {
        UIAlertView *errorAlertView = [[UIAlertView alloc] initWithTitle:@"Attention" message:[error localizedDescription] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [errorAlertView show];
    }
}

错误:

The operation couldn't be completed. (Cocoa error 513).


推荐答案

正如@cahn所说,你的应用被拒绝了,因为许可问题。即使安装在 / Applications / 中,应用程序通常以用户 mobile 运行。正如您在此登录会话中看到的那样:

As @cahn said, your app is being denied because of a permission problem. Even if installed in /Applications/, apps normally run as user mobile. As you can see from this login session:

$ ssh mobile@iphone5
mobile@iphone5's password: 
iPhone5:~ mobile$ cd /var
iPhone5:/var mobile$ mkdir mydir
mkdir: cannot create directory `mydir': Permission denied

移动用户没有直接在 / var / 下的写权限。

the mobile user doesn't have write permissions directly under /var/.

如果你看看在本文档中关于在thebigboss.org上构建Cydia应用程序,你会看到他们建议越狱应用程序在 / var / mobile /创建文档目录Library / YOURAPPNAME

If you take a look at this document on building Cydia apps on thebigboss.org, you'll see that they recommend that jailbreak apps create documents directories at /var/mobile/Library/YOURAPPNAME:


1)Appstore应用程序在
/ var / mobile的沙箱中运行/应用/ GUID /文件夹。越狱应用程序以
/应用程序运行

1) Appstore app runs in a sandbox at /var/mobile/Applications/GUID/folder. Jailbroken app runs in /Applications

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

2) 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.

这篇关于为什么我会得到“Cocoa error 513”将文件写入“/ var / mydir / files”时在越狱的iPhone上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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