我目前正在使用的 iOS 应用程序遇到了一个非常奇怪的问题。仅当我使用 ad hoc 分发测试应用程序时,效果才会存在。更新应用程序(必须先安装)后,它无法正常工作。我可以追踪错误,它是由以下代码行引起的:
[fileManager createDirectoryAtPath:folder withIntermediateDirectories:YES attributes:nil error:&error];
现在您当然可以说:永远不要写入应用程序包本身,但基本路径是 Documents 文件夹,通过:
dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = [dirPaths objectAtIndex:0];
imgDir = [docsDir stringByAppendingPathComponent:@"images"];
folder = [imgDir stringByAppendingPathComponent:md5]; // md5-Hash is created before
完整的错误消息(记录到 iphone 系统日志)是:
错误域 = NSCocoaErrorDomain 代码 = 513 “操作无法完成。(可可错误 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 或直接写入应用程序包。也许其他人有问题或有想法?