UIDocumentInteractionController与iOS7 iPhone上的奇怪行为

问题描述:

我打了两天的问题现在墙壁,我想你的帮助。在我开始之前,我应该说这个问题是在iOS7上的iPhone 5上(我也在iOS 6和iPad 2上使用iOS 7的iPhone 4上测试过)。当我试图升级已经在AppStore上的应用程序(最初是iOS4)并试图使其与iOS 7兼容(在iOS6以上支持)时,此问题就开始了。UIDocumentInteractionController与iOS7 iPhone上的奇怪行为

这个场景很简单。我有一个与UIDocumentInteractionControllerDelegate视图。我从网络服务下载文件,将其保存在NSTemporaryDirectory中,并允许用户在使用presentOptionsMenuFromRect的另一个应用程序中预览或打开。代码简化如下:

我已经声明@property(nonatomic,strong)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]; 
    }  
} 

的问题是,我收到的所有类型的错误,我重复同样的过程中所有的时间,我得到不同的错误,有时它的作品多次在一排,有时从第一次去失败。我收到除其他错误,当我再次得到他们,我将增加为:

  1. *终止应用程序由于未捕获的异常“NSGenericException”,原因是:“*收藏< __NSSetM:0x16ff61e0>突变而列举了 '。

  2. 的malloc:*错误对象0x177a56a4:为 释放对象不正确的校验 - 对象是在被释放后,可能被修改。

  3. 的malloc:*错误对象0x1c2c8b50:双自由*设置malloc_error_break一个 断点调试

当OptionsMenu成功表明我看到“空投:的CollectionView:布局:insetForSectionAtIndex: ,orientation:1,sectionInset:{0,10,0,10}“。

我试过启用NSZombies,并为malloc错误放置断点,但没有以任何方式帮助我。

请帮助我或引导我走向正确的方向。

谢谢。

+0

请人之前添加延迟? ? –

+0

您是否尝试过没有autorelease池封装它的相同代码? – ccjensen

+0

是的,我做了但没有任何区别。我也尝试添加几段代码到try catch块中,但是我再也没有发现任何异常 –

有点晚回答,但希望它会帮助其他人。

当保存文件和呈现UIDocumentInteractionController时,我遇到了完全相同的问题,它绝对是随机的,有时它会连续完成10次,有时会在第一次尝试时崩溃。

这似乎是由文件引起不必完成写入磁盘,有什么固定的,对我来说是呈现UIDocumentInteractionController,以确保该文件已完成写入磁盘

+0

我也经历过同样的事情。 – siva