CameraController
open class CameraController: NSObject, LensRepositoryGroupObserver, LensPrefetcherObserver, LensHintDelegate,
MediaPickerViewDelegate, AdjustmentControlViewDelegate
A controller which manages the camera and lenses stack on behalf of its owner
-
A capture session we’ll use for camera input.
Declaration
Swift
public let captureSession: AVCaptureSession
-
The CameraKit session
Declaration
Swift
public let cameraKit: CameraKitProtocol
-
The position of the camera.
Declaration
Swift
public private(set) var cameraPosition: AVCaptureDevice.Position { get set }
-
An output used for taking still photos.
Declaration
Swift
public private(set) var photoCaptureOutput: PhotoCaptureOutput? { get }
-
An output used for recording videos.
Declaration
Swift
public private(set) var recorder: Recorder? { get }
-
Media provider for CameraKit.
Declaration
Swift
public let lensMediaProvider: LensMediaPickerProviderPhotoLibrary
-
Snapchat delegate for requests to open the main Snapchat app.
Declaration
Swift
public weak var snapchatDelegate: SnapchatDelegate?
-
Delegate for responding to UI requests from camera controller.
Declaration
Swift
public weak var uiDelegate: CameraControllerUIDelegate?
-
The currently selected and active lens.
Declaration
Swift
public private(set) var currentLens: Lens? { get }
-
List of lens repository groups to observe/show in carousel
Declaration
Swift
public var groupIDs: [String] { get set }
-
Whether or not the tone map adjustment is available for the current device. This variable should be checked before showing any UI associated with the tone map adjustment.
Declaration
Swift
public var isToneMapAdjustmentAvailable: Bool { get }
-
Whether or not the portrait adjustment is available for the current device. This variable should be checked before showing any UI associated with the portrait adjustment.
Declaration
Swift
public var isPortraitAdjustmentAvailable: Bool { get }
-
The current state of the camera flash.
Declaration
Swift
public var flashState: FlashState { get set }
-
Returns a camera controller that is initialized with a newly created AVCaptureSession stack and CameraKit session with the specified configuration and list of group IDs.
Declaration
Swift
public convenience init(sessionConfig: SessionConfig? = nil)
Parameters
sessionConfig
Config to configure session with application id and api token. Pass this in if you wish to dynamically update or overwrite the application id and api token in the application’s
Info.plist
. -
Init with camera kit session, capture session, and lens holder
Declaration
Swift
public init(cameraKit: CameraKitProtocol, captureSession: AVCaptureSession)
Parameters
cameraKit
camera kit session
captureSession
avcapturesession
-
Configures the overall camera and lenses stack.
Declaration
Swift
public func configure( orientation: AVCaptureVideoOrientation, textInputContextProvider: TextInputContextProvider?, agreementsPresentationContextProvider: AgreementsPresentationContextProvider?, completion: (() -> Void)? )
Parameters
orientation
the orientation
completion
a nullable completion that is called after configuration is done. In case it’s a first app start (when camera permission is not determined yet) a completion will be called after the prompt.
-
Configures the lenses pipeline.
Declaration
Swift
open func configureLenses( orientation: AVCaptureVideoOrientation, textInputContextProvider: TextInputContextProvider?, agreementsPresentationContextProvider: AgreementsPresentationContextProvider? )
Parameters
orientation
the camera orientation.
-
Configures the data provider for lenses. Subclasses may override this to customize their data provider.
Declaration
Swift
open func configureDataProvider() -> DataProviderComponent
Return Value
a configured data provider.
-
Zoom in by a given factor from whatever the current zoom level is
Note
the zoom level will be capped to a minimum level of 1.0.Declaration
Swift
public func zoomExistingLevel(by factor: CGFloat)
Parameters
factor
the factor to zoom by.
-
Save whatever the current zoom level is.
Declaration
Swift
public func finalizeZoom()
-
Flips the camera to the other side
Declaration
Swift
public func flipCamera()
-
Options to support when setting a point of interest
See moreDeclaration
Swift
public struct PointOfInterestOptions : OptionSet
-
Sets camera point of interest for operations in the option set. Also adds observers for the current device such that once the focusing/exposure rebalancing operations are complete, continuous autofocus/autoexposure are restored (see observeValue)
Declaration
Swift
public func setPointOfInterest(at point: CGPoint, for options: PointOfInterestOptions = [.exposure, .focus])
-
Takes a photo.
Declaration
Swift
public func takePhoto(completion: ((UIImage?, Error?) -> Void)?)
Parameters
completion
completion to be called with the photo or an error.
-
Undocumented
Declaration
Swift
open func repository(_ repository: LensRepository, didUpdateLenses lenses: [Lens], forGroupID groupID: String)
-
Undocumented
Declaration
Swift
open func repository( _ repository: LensRepository, didFailToUpdateLensesForGroupID groupID: String, error: Error? )
-
Undocumented
Declaration
Swift
public func prefetcher(_ prefetcher: LensPrefetcher, didUpdate lens: Lens, status: LensFetchStatus)
-
Begin recording video.
Declaration
Swift
public func startRecording()
-
Cancel recording video.
Declaration
Swift
public func cancelRecording()
-
Finish recording the video.
Declaration
Swift
public func finishRecording(completion: ((URL?, Error?) -> Void)?)
Parameters
completion
completion to be called with a URL to the recorded video or an error.
-
Apply a specified lens.
Declaration
Swift
public func applyLens(_ lens: Lens, completion: ((Bool) -> Void)? = nil)
Parameters
lens
selected lens
completion
callback on completion with success/failure
-
Clear the currently selected lens, and return to unmodified camera feed.
- willReapply: if true, cameraKit will not clear out the “currentLens” property, and reapplyCurrentLens will apply the lens that was cleared.
- completion: callback on completion with success/failure
Declaration
Swift
public func clearLens(willReapply: Bool = false, completion: ((Bool) -> Void)? = nil)
-
If a lens has already been applied, reapply it.
Declaration
Swift
public func reapplyCurrentLens()
-
Enables the tone map adjustment.
Note
Before calling this function, check whether or not the adjustment is available for the device. SeeisToneMapAdjustmentAvailable
.Declaration
Swift
public func enableToneMapAdjustment() -> Float?
Return Value
Float representing the intensity of the tone map effect.
-
Disables the tone map adjustment.
Declaration
Swift
public func disableToneMapAdjustment()
-
Enables the portrait adjustment.
Note
Before calling this function, check whether or not the adjustment is available for the device. SeeisPortraitAdjustmentAvailable
.Declaration
Swift
public func enablePortraitAdjustment() -> Float?
Return Value
Float representing the intensity of the portrait blur effect.
-
Disables the portrait adjustment.
Declaration
Swift
public func disablePortraitAdjustment()
-
Undocumented
Declaration
Swift
public func lensProcessor( _ lensProcessor: LensProcessor, shouldDisplayHint hint: String, for lens: Lens, autohide: Bool )
-
Undocumented
Declaration
Swift
public func lensProcessor(_ lensProcessor: LensProcessor, shouldHideAllHintsFor lens: Lens)
-
Declaration
Swift
public func mediaPickerView(_ mediaPickerView: MediaPickerView, selectedAsset: LensMediaPickerProviderAsset)
-
Declaration
Swift
public func adjustmentControlView(_ control: AdjustmentControlView, sliderValueChanged value: Double)
-
Temporary state that holds the brightness that should be restored after the ring light is disabled.
Declaration
Swift
public var brightnessToRestore: CGFloat?
-
Enumerates the different flash enabled modes.
See moreDeclaration
Swift
public enum FlashMode : Int
-
Enumerates the different possible flash states.
See moreDeclaration
Swift
public enum FlashState : Equatable
-
Enables the camera flash with the appopriate flash mode as per camera position and prior user selections.
Declaration
Swift
public func enableFlash()
-
Disables the camera flash.
Declaration
Swift
public func disableFlash()
-
Restores brightness to what it was before the ring light was enabled.
Declaration
Swift
public func restoreBrightnessIfNecessary()
-
Increases brightness to max if the ring light is enabled.
Declaration
Swift
public func increaseBrightnessIfNecessary()