【问题标题】:UIImageWriteToSavedPhotosAlbum freezes the appUIImageWriteToSavedPhotosAlbum 冻结应用
【发布时间】:2016-04-25 02:28:09
【问题描述】:

所以我有一个有趣的问题。

当我调用 UIImageWriteToSavedPhotosAlbum 时,它会冻结我的应用程序,我不知道为什么。

这就是我的代码

UIImageWriteToSavedPhotosAlbum(leftImage, self,  @selector(image:didFinishSavingWithError:contextInfo:), nil);

UIImageWriteToSavedPhotosAlbum(rightImage, self,  @selector(image:didFinishSavingWithError:contextInfo:), nil);

- (void)image:(UIImage *)image didFinishSavingWithError:(NSError  *)error contextInfo: (void *)contextInfo
{
  if (error != nil)
  {
    NSLog(@"Image Can not be saved");
  }
  else
  {
    NSLog(@"Successfully saved Image");
  }
}

所以有时有效,有时无效。当我删除这两行时,它永远不会冻结。会出什么问题。我假设我看不到didFinishSavingWithError,因为应用程序冻结了。

这里是堆栈

【问题讨论】:

  • 它是崩溃还是冻结?你两个都说。
  • 定义冻结。你的意思是主线程块还是别的什么?
  • @rmaddy 无法触摸 UI 上的任何按钮。不确定这是否与应用相关,但主页按钮没有响应。
  • 当您的应用程序冻结时,单击 Xcode 调试器中的“暂停”按钮并查看主线程的堆栈跟踪。看看它在做什么。
  • @rmaddy 我得到了照片。我对堆栈没有最好的理解

标签: ios objective-c uiimageview


【解决方案1】:

问题是你连续调用了两次这个方法:

UIImageWriteToSavedPhotosAlbum(leftImage, self,  @selector(image:didFinishSavingWithError:contextInfo:), nil);
UIImageWriteToSavedPhotosAlbum(rightImage, self,  @selector(image:didFinishSavingWithError:contextInfo:), nil);

但该方法需要时间才能完成。在它完成之前,您不能再次调用它。这就是didFinishSavingWithError 的用途——它让您知道它何时完成,因此再次调用它是安全的。

因此,解决方案是,在第一次调用您的 didFinishSavingWithError 之前,不要第二次调用 UIImageWriteToSavedPhotosAlbum。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-06-17
    • 2011-08-16
    • 1970-01-01
    • 2019-11-04
    • 2015-05-09
    • 2013-09-26
    • 2014-09-29
    • 2016-02-10
    相关资源
    最近更新 更多