【发布时间】:2014-07-24 18:42:32
【问题描述】:
我有一种将照片保存到用户照片库的方法。此代码在您第一次将照片保存到图库时运行良好,但如果您再次尝试保存,应用程序将崩溃。
方法如下:
- (void)saveToLibray
{
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
// Request to save the image to camera roll
[library writeImageToSavedPhotosAlbum:[self.image CGImage] orientation:(ALAssetOrientation)[self.image imageOrientation] completionBlock:^(NSURL *assetURL, NSError *error){
if (error) {
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:nil message:@"Could not save photo to your library. Please enable Halfsies in Settings > Privacy > Photos." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
CGImageRelease([self.image CGImage]);
} else if (!error) {
UIAlertView *librarySaveSuccessAlertView = [[UIAlertView alloc]initWithTitle:@"Success!" message:@"Your finished halfsie was successfully saved to your photo library!" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[librarySaveSuccessAlertView show];
CGImageRelease([self.image CGImage]);
}
}];
}
我已确定释放CGImage,我也在等待librarySaveSuccessAlertView 显示在屏幕上,单击它的确定按钮(cancelButtonTitle),然后我再次尝试保存。
第二次应用总是崩溃。
这是因为图书馆可以检测到重复的照片,还是其他原因?
编辑:崩溃详情
在应用程序崩溃后以绿色突出显示的行上显示:
Thread 1: EXC_BAD_ACCESS(code=1, address=0x657471ef)
编辑 2:好的,所以我现在意识到这很可能是因为我正在尝试向已发布的对象发送消息。我很困惑我应该如何处理这个问题。即使我释放了self.image 的CGImage 数据,我应该仍然能够在第二次保存时再次访问它对吗?
【问题讨论】:
-
崩溃是什么?你知道,这些东西通常信息量很大。不要只说“它崩溃了”。实际发生了什么?它可能与您刚刚显示的代码无关......
-
能把崩溃的日志放上来
-
抱歉,我没有太多的调试经验。请查看我的编辑。
-
请看我的第二次编辑。
-
你已经解决了这个问题,但是,僵尸是一个很好的技术。
标签: ios alassetslibrary