在captureStillImageAsynchronouslyFromConnection之后调用void

时间:2014-09-19 16:16:02

标签: ios objective-c completionhandler

我正试图在

时运行void saveImageToLibrary
[self.avSnapper captureStillImageAsynchronouslyFromConnection:captureConnection
                                                completionHandler:handler]; 

完成了。我该怎么做呢?

2 个答案:

答案 0 :(得分:0)

如果需要在函数完成时运行一些代码,则会出现“completionHandler”参数。

根据documentation:“在捕获图像后调用的块。”。

编辑:您可以阅读有关编程here的块。由于块符号可能有点令人困惑,因此有一个简单的技巧可以帮助您。使用自动完成功能在XCode中创建函数签名时,您需要为要传递的变量设置蓝色占位符。现在,当你在块占位符上点击'enter'时,XCode会为你生成具有匹配语法的空块。

答案 1 :(得分:0)

我觉得这就是你想要的东西

[self.avSnapper captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler: ^(CMSampleBufferRef imageSampleBuffer, NSError *error){

     CFDictionaryRef exifAttachments = CMGetAttachment( imageSampleBuffer, kCGImagePropertyExifDictionary, NULL);
     if (exifAttachments){

        // Do something with the attachments if you want to. 
        NSLog(@"attachements: %@", exifAttachments);
    }
    else
        NSLog(@"no attachments");

    NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer];
    UIImage *image = [[UIImage alloc] initWithData:imageData];

    self.vImage.image = image;
}];