captureStillImageAsynchronously(from:completionHandler:)
Initiates a still image capture and returns immediately.
Declaration
func captureStillImageAsynchronously(from connection: AVCaptureConnection, completionHandler handler: @escaping (CMSampleBuffer?, (any Error)?) -> Void)Parameters
- connection:
The connection from which to capture the image.
- handler:
A block to invoke after the image has been captured. The block parameters are as follows:
- imageDataSampleBuffer
The data that was captured.
The buffer attachments may contain metadata appropriate to the image data format. For example, a buffer containing JPEG data may carry a Kcgimagepropertyexifdictionary as an attachment. See ImageIO/CGImageProperties.h for a list of keys and value types.
- error
If the request could not be completed, an
NSErrorobject that describes the problem; otherwisenil.
Discussion
This method returns immediately after it is invoked, later calling the provided completion handler block when image data is ready. If the request could not be completed, the error parameter will contain an NSError object describing the failure.
You should not assume that the completion handler will be called on a specific thread.