0

我将我的项目转换为 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);
    }
}];
4

2 回答 2

1

请注意,在应用程序的整个生命周期中,您应该只初始化一次资产库。因此,您应该例如在 appdelegate 或另一个单例中执行此操作。您的代码似乎有风险帽子资产库被多次初始化。

干杯,

亨德里克

于 2012-05-16T18:42:08.770 回答
0

有时生活可以如此艰难。在 ARC 之前,我不必保留 CFDictionaryRef。所以添加 CFRetain(attachments); 初始化附件后,删除了错误的访问权限。

干杯,浴缸

于 2013-01-06T22:34:45.400 回答