我现在在墙上遇到问题两天了,我希望得到你的帮助。在我开始之前,我应该说这个问题出现在带有iOS7的iPhone 5上(我已经在iPhone 4上测试了iOS 6和iPad 2测试了iOS 7)。当我尝试升级已经在AppStore上的应用程序(最初是iOS4)并尝试使其兼容iOS 7(从iOS6开始支持)时,就会出现此问题。
场景非常简单。我有一个视图是一个UIDocumentInteractionControllerDelegate。我从Web服务下载文件,将其保存在NSTemporaryDirectory上,并允许用户使用presentOptionsMenuFromRect在另一个应用程序中预览或打开。简化的代码如下:
我已声明@property(非原子,强)UIDocumentInteractionController * docController;
@autoreleasepool {
NSString *fileName = "uniquefilename"
NSString *filePath = [NSTemporaryDirectory() stringByAppendingPathComponent:fileName];
fileURL = [NSURL fileURLWithPath:filePath];
NSFileManager *fileManager = [NSFileManager defaultManager];
if(![fileManager fileExistsAtPath:filePath]){
NSData *fileData = [NSData dataWithContentsOfURL:[NSURL URLWithString:"theurlofthefile"]];
NSError *writeError = nil;
[fileData writeToURL: fileURL options:0 error:&writeError];
if(writeError) {
//show error
}
}
docController = [UIDocumentInteractionController interactionControllerWithURL:url];
docController.delegate = self;
if (isIpad) {
[docController presentOptionsMenuFromRect:CGRectMake(location.x + 400,location.y, 100, 100) inView:tableView animated:YES];
}
else{
[docController presentOptionsMenuFromRect:CGRectZero inView:self.tabBarController.view animated:YES];
}
}
问题是我收到了所有类型的错误,我一直重复同样的过程而且我得到不同的错误,有时它连续多次工作,有时它从第一次开始就失败了。当我再次获得它们时,我将收到的错误是:
*由于未捕获的异常'NSGenericException'而终止应用程序,原因:'* 集合< __ NSSetM:0x16ff61e0>在变异的同时 被列举。'
malloc: * 错误:校验和错误 释放的对象 - 对象可能在被释放后被修改。
malloc: *对象0x1c2c8b50的错误:double free * 设置a malloc_error_break中的断点调试
当OptionsMenu成功显示时,我在控制台中看到“AirDrop:collectionView:layout:insetForSectionAtIndex:,orientation:1,sectionInset:{0,10,0,10}”。
我尝试启用NSZombies并为malloc错误设置断点,但没有以任何方式帮助我。
请帮助我或指导我正确的方向。
谢谢。
答案 0 :(得分:3)
迟到的回答,但希望它会帮助其他人。
我在保存文件和呈现UIDocumentInteractionController时遇到了完全相同的问题,它有时绝对是随机的,它会连续10次完成,有时会在第一次尝试时崩溃。
这似乎是由于文件没有完成写入磁盘造成的,修复它的原因是在呈现UIDocumentInteractionController之前添加延迟以确保文件已写入磁盘