【发布时间】:2012-04-03 08:25:16
【问题描述】:
我将我的项目转换为 arc,现在,当我实例化一个新的资产库时,它会引发错误的访问错误。在 ARC 之前没有问题。
有什么建议吗?
[self.stillImageOutput captureStillImageAsynchronouslyFromConnection:stillImageConnection
completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error)
{
if (error) {
NSLog(@"Take picture failed");
}
else
{
NSData *jpegData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];
CFDictionaryRef attachments = CMCopyDictionaryOfAttachments(kCFAllocatorDefault,
imageDataSampleBuffer,
kCMAttachmentMode_ShouldPropagate);
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library writeImageDataToSavedPhotosAlbum:jpegData
metadata:(__bridge_transfer id)attachments
completionBlock:^(NSURL *assetURL, NSError *error) {
if (error) {
NSLog(@"Save to camera roll failed");
}
}];
if (attachments)
CFRelease(attachments);
}
}];
【问题讨论】:
-
有时生活会如此艰难。在 ARC 之前,我不必保留 CFDictionaryRef。所以在初始化附件后添加
CFRetain(attachments);删除了错误的访问。干杯, -
请将您的解决方案放在答案而不是评论中:blog.stackoverflow.com/2011/07/…
标签: cocoa-touch avfoundation alassetslibrary image-capture