UIImageWriteToSavedPhotosAlbum冻结应用程序

时间:2016-04-25 02:28:10

标签: ios objective-c uiimageview

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

当我致电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,因为该应用程序冻结了。

这是堆栈 enter image description here

1 个答案:

答案 0 :(得分:0)

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

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

但该方法需要时间才能完成。在完成之前,您无法再次呼叫它。那是didFinishSavingWithError的用途 - 它让您知道它何时完成,因此再次调用它是安全的。

因此,解决方案是,不要再次致电UIImageWriteToSavedPhotosAlbum,直到第一次调用didFinishSavingWithError为止。

相关问题