【发布时间】:2014-03-10 00:19:15
【问题描述】:
我目前正在使用的 iOS 应用程序遇到了一个非常奇怪的问题。仅当我使用 ad hoc 分发测试应用程序时,效果才会存在。更新应用程序(必须先安装)后,它无法正常工作。我可以追踪错误,它是由以下代码行引起的:
[fileManager createDirectoryAtPath:folder withIntermediateDirectories:YES attributes:nil error:&error];
现在您当然可以说:永远不要写入应用程序包本身,但基本路径是 Documents 文件夹 via:
dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = [dirPaths objectAtIndex:0];
imgDir = [docsDir stringByAppendingPathComponent:@"images"];
folder = [imgDir stringByAppendingPathComponent:md5]; // md5-Hash is created before
完整的错误信息(记录到iphone系统日志)是:
Error Domain=NSCocoaErrorDomain Code=513 “操作无法完成。(Cocoa 错误 513。)” UserInfo=0x14d44f30 {NSFilePath=/var/mobile/Applications/280C6D36-3667-4589-A74F-42F3F17ABA71/Documents /images/39b6cd45a05a2276ef065b2ecf33b1eb, NSUnderlyingError=0x14d4e340 "操作无法完成。操作不允许"}
有趣的是,正如我所指出的,如果我在通过临时分发安装之前删除应用程序(Testflight 到带有 iOS 7.0.4 的 iPhone 5),则会创建文件夹并且应用程序按预期工作。我能找到的唯一参考资料是开发人员不使用 stringByAppendingPathComponent 或直接写入应用程序包。也许其他人有问题或有想法?
【问题讨论】:
-
你是不是不小心在同一个路径重复写入同一个文件夹名?
-
当我使用不同 url 的 md5-Hash 作为文件夹名称时,我会说:不可能。但可以肯定的是,我只是仔细检查了一下,不,该文件夹以前不存在。
-
+1 表示写得很好的问题,包括记录对您不起作用或不适用于您的案例的潜在解决方案。
标签: ios iphone objective-c ad-hoc-distribution create-directory