在iPhone上创建文件夹的权限 [英] Permission to create folder on iPhone

查看:739
本文介绍了在iPhone上创建文件夹的权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

经过一半的挖掘,我发现我没有创建文件夹的权限,所以如何获得创建文件夹的权限?

After like a half an our of digging, I've found out I don't have permission to create folders, so how do I get permission to create a folder?

[[NSFileManager defaultManager] createDirectoryAtPath:[NSString stringWithFormat:@"%@/%@",downloadLocation,kAmazonCatalogsPrefix]
                          withIntermediateDirectories:YES
                                           attributes:nil
                                                error:&error];

Error Domain=NSCocoaErrorDomain Code=513 "The operation couldn’t be completed. (Cocoa error 513.)" UserInfo=0x1f18a8b0 {NSFilePath=/var/mobile/Applications/AB570058-4E4A-41B2-9E40-5C93316D6307/eCatalogs, NSUnderlyingError=0x1f18a830 "The operation couldn’t be completed. Operation not permitted"}


推荐答案

您无法修改已编译应用程序的包文件夹的内容。这是因为bundle是已编译的应用程序。这可以防止安装后恶意软件修改应用程序的可能性。

You cannot modify the contents of a compiled app's bundle folder. This is because the bundle is the compiled application. This prevents the possibility of malware modifying apps after install.

运行时生成的文件应保存到 Documents Temp 缓存文件夹。这些文件夹只能供您的应用访问。没有其他应用可以访问这些文件夹的内容。

Files generated at run time should be saved to the either Documents, Temp or Cache folders. These folders are only accessible to your app. No other app can access the contents of these folders.

示例代码:

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

NSError *error;
[[NSFileManager defaultManager] createDirectoryAtPath:[documentsDirectory stringByAppendingPathComponent:@"yourFolderName"] withIntermediateDirectories:NO attributes:nil error:&error];

这篇关于在iPhone上创建文件夹的权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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