所以我有一个有趣的问题。
当我调用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
,因为应用程序冻结了。
这是堆栈
发布于 2016-04-25 14:00:48
问题是您连续两次调用此方法:
UIImageWriteToSavedPhotosAlbum(leftImage, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
UIImageWriteToSavedPhotosAlbum(rightImage, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
但是这个方法需要时间来完成。在它完成之前,您不能第二次调用它。这就是didFinishSavingWithError
的作用--这样你就知道它什么时候完成了,所以再次调用它是安全的。
因此,解决方案是,在第一次调用didFinishSavingWithError
之前,不要第二次调用UIImageWriteToSavedPhotosAlbum
。
https://stackoverflow.com/questions/36831156
复制相似问题