NSFileManager创建文件夹(可可错误513.) [英] NSFileManager creating folder (Cocoa error 513.)

查看:173
本文介绍了NSFileManager创建文件夹(可可错误513.)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的应用程序的/sounds文件夹中创建一个文件夹.

I'm trying to create a folder inside the /sounds folder of my app.

-(void)productPurchased:(UAProduct*) product {
    NSLog(@"[StoreFrontDelegate] Purchased: %@ -- %@", product.productIdentifier, product.title);

    NSFileManager *manager = [NSFileManager defaultManager];
    NSString *bundleRoot = [[NSBundle mainBundle] bundlePath];

    NSError *error;

    NSString *dataPath = [NSString stringWithFormat:@"%@/sounds/%@", bundleRoot, product.title];

    if (![manager fileExistsAtPath:dataPath isDirectory:YES]) {
        [manager createDirectoryAtPath:dataPath withIntermediateDirectories:YES attributes:nil error:&error];
        NSLog(@"Creating folder");
    }

    NSLog(@"%@", error);
}

但是我得到这个错误:

Error Domain=NSCocoaErrorDomain Code=513 "The operation couldn’t be completed. (Cocoa error 513.)" UserInfo=0x175120 {NSFilePath=/var/mobile/Applications/D83FDFF9-2600-4056-9047-05F82633A2E4/App.app/sounds/Test Tones, NSUnderlyingError=0x117520 "The operation couldn’t be completed. Operation not permitted"}

我做错了什么? 谢谢.

What am I doing wrong? Thanks.

推荐答案

如果您在错误域 NSFileWriteNoPermissionError .

If you search Google on the error domain NSCocoaErrorDomain you find that the code 513 translates to the error NSFileWriteNoPermissionError.

这为您提供了解决此问题的关键线索:

This provides you with the critical clue for solving this problem:

这是包含应用程序本身的捆绑目录.由于必须对应用程序进行签名,因此您不能在运行时更改此目录的内容.这样做可能会阻止您的应用程序稍后启动.

具体来说,您不能修改已编译应用程序的捆绑文件夹的内容.这是因为捆绑包是已编译的应用程序.

Specifically, you cannot modify the contents of a compiled app's bundle folder. This is because the bundle is the compiled application.

当您最终通过iTunes App Store分发应用程序时,该应用程序具有数字签名,可验证该应用程序的内容.此签名是在编译时生成的.

When you eventually distribute the app through the iTunes App Store, the application has a digital signature that validates the contents of the app. This signature is generated at compile time.

如果您尝试在编译后更改捆绑软件,则应用程序将更改并且数字签名不再有效.这会使应用程序无效-谁知道其中包含什么代码,对吗? —最终用户将无法运行它.因此,如果您尝试修改捆绑软件,Apple已将iOS设置为抛出错误.

If you try to change the bundle after compilation, the app changes and the digital signature is no longer valid. This invalidates the application — who knows what code is in there, right? — and end users won't be able to run it. So Apple has set up iOS to throw an error if you try to modify the bundle.

您的应用程序可以写入

Instead of writing to the bundle, your app can write to one of three accepted app-specific folders: Documents, Temp and Cache. Most likely, you will want to write to the Documents folder.

这些文件夹只能由您的应用访问.没有其他应用程序可以访问这些文件夹的内容. (同样,您的应用程序无法访问其他应用程序的文件夹.)

These folders are only accessible to your app. No other app can access the contents of these folders. (Likewise, your app cannot access another app's folders.)

您可以将应用程序设置为允许最终用户通过

You can set up your app to allow the end user to manage access to file data through iTunes, via desktop file sharing support.

这篇关于NSFileManager创建文件夹(可可错误513.)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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