0

I'm trying to run a void saveImageToLibrary when

[self.avSnapper captureStillImageAsynchronouslyFromConnection:captureConnection
                                                completionHandler:handler]; 

is done. How would I go about it?

suMi
  • 1,536
  • 1
  • 17
  • 30

2 Answers2

0

If you need to run some code at function completion, there is "completionHandler" parameter.

According to documentation: "A block to invoke after the image has been captured.".

Edit: You can read about blocks programming here. As a block notation can be a bit confusing, there is a simple trick that may help you. When you create function signature in XCode using autocompletion, you have blue placeholders for variables you need to pass. Now, when you hit 'enter' on block placeholder, XCode generates empty block with matching syntax for you.

Maciej Kozieł
  • 959
  • 11
  • 24
  • I'm not sure what do you asking for. You don't understand block notation? You don't know how to save image? Please specify your question. – Maciej Kozieł Sep 19 '14 at 16:26
  • I don't know "block notation" I don't even know what you're talking about – suMi Sep 19 '14 at 16:29
0

I thing this is what you want

[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;
}];
mhrrt
  • 977
  • 9
  • 18
  • I think I need some explanation. what is this? "^(CMSampleBufferRef imageSampleBuffer, NSError *error)" ? I obviously need a different function there so I need to understand what it's doing and how to just call a void there – suMi Sep 19 '14 at 16:33
  • What do you mean by "call a void"? As for notation you don't understand, I've added url to explanation in my answer. – Maciej Kozieł Sep 19 '14 at 16:37
  • @suMi here ^ is block notation, things written with in ^ notation will be executed with said parameters once a "captureStillImageAsynchronouslyFromConnection:" get finish off. For more you need to get familiar with "Blocks in iOS" in ios.you can also look at http://www.raywenderlich.com/9438/how-to-use-blocks-in-ios-5-tutorial-part-2 – mhrrt Sep 19 '14 at 17:04