setDeferredStartDelegate(_:deferredStartDelegateCallbackQueue:)
Sets a delegate object for the session to call when performing deferred start.
Declaration
func setDeferredStartDelegate(_ deferredStartDelegate: (any AVCaptureSessionDeferredStartDelegate)?, deferredStartDelegateCallbackQueue: dispatch_queue_t?)Parameters
- deferredStartDelegate:
An object conforming to the Avcapturesessiondeferredstartdelegate protocol that receives events about deferred start.
- deferredStartDelegateCallbackQueue:
A dispatch queue on which deferredStart delegate methods are called.
Discussion
This delegate receives a call to the sessionWillRunDeferredStart(_:) method when deferred start is about to run. It is non-blocking, so by the time this method is called, the deferred start may already be underway. If you want your app to perform initialization (potentially) concurrently with deferred start (e.g. user-facing camera features that are not needed to display the first preview frame, but are available to the user as soon as possible) it may be done in the delegate’s sessionWillRunDeferredStart(_:) method. To wait until deferred start is finished to perform some remaining initialization work, use the sessionDidRunDeferredStart(_:) method instead.
The delegate receives a call to the sessionDidRunDeferredStart(_:) method when the deferred start finishes running. This allows you to run less-critical application initialization code. For example, if you’ve deferred an AVCapturePhotoOutput by setting its isDeferredStartEnabled property to true, and you’d like to do some app-specific initialization related to still capture, here might be a good place to put it.
If the delegate is non-nil, the session still calls the sessionWillRunDeferredStart(_:) and sessionDidRunDeferredStart(_:) methods regardless of the value of the session’s automaticallyRunsDeferredStart property.
To minimize the capture session’s startup latency, defer all unnecessary work until after the session starts. This delegate provides callbacks for you to schedule deferred work without impacting session startup performance.
To perform initialization prior to deferred start but after the user interface displays, set automaticallyRunsDeferredStart to false, and then run the custom initialization prior to calling runDeferredStartWhenNeeded().
If deferredStartDelegate is not NULL, the session throws an exception if deferredStartDelegateCallbackQueue is nil.