Cocoa touch 块内库的实例化引发错误访问

Cocoa touch 块内库的实例化引发错误访问,cocoa-touch,avfoundation,alassetslibrary,image-capture,Cocoa Touch,Avfoundation,Alassetslibrary,Image Capture,我将我的项目转换为arc,现在,当我实例化一个新的资产库时,它抛出了一个错误的访问错误。在ARC之前没有问题 有什么建议吗 [self.stillImageOutput captureStillImageAsynchronouslyFromConnection:stillImageConnection completionHandler:^(CMSampleBufferRef imageData

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

请注意,在应用程序的整个生命周期中,您只应初始化assetlibrary一次。因此,您应该在appdelegate或其他单例中这样做。您的代码似乎存在资产库多次初始化的风险

干杯


亨德里克有时候生活会很艰难。在ARC之前,我不必保留CFDictionaryRef。因此,增加了CFRetain(附件);初始化附件后,删除了错误访问

干杯,
有时候生活会很艰难。在ARC之前,我不必保留CFDictionaryRef。因此,添加
CFRetain(附件)初始化附件后,删除了错误访问。干杯,请在回答中加入您的解决方案,而不是评论: