Camera
Defined in framework ScanditCaptureCore
- enum TorchState
Added in version 6.0.0
Possible values for the torch state.
- on
Added in version 6.0.0
Value to indicate that the torch is turned on.
- off
Added in version 6.0.0
Value to indicate that the torch is turned off.
- auto
Added in version 6.3.0
Value to indicate that the torch is managed automatically. The torch is turned on or off based on the available illumination.
Note
This is an experimental feature. This functionality may or may not work for your use case or may be removed in future version of this software.
- TorchListener
protocol TorchListener : NSObjectProtocol
Added in version 6.3.0
Interface definition for a callback to be invoked when the TorchState of a Camera changes.
- didChangeTorch
open func didChangeTorch(to torchState: TorchState) ->
VoidAdded in version 6.3.0
Called when TorchState changed.
- MacroModeListener
protocol MacroModeListener : NSObjectProtocol
Added in version 6.17.0
Interface definition for a callback to be invoked when the MacroMode of a Camera changes.
- Camera
open class Camera : NSObject, FrameSource
Added in version 6.0.0
Gives access to the built-in camera on iOS. It implements the FrameSource interface, and, as such can be set as the frame source for the DataCaptureContext.
Instances of this class are created through one of the factory methods `default`(), or init().
The camera is started by changing the desired state to FrameSourceState.on.
By default, the resolution of captured frames as well as auto-focus and exposure settings are chosen such that they work best for a variety of use cases. To fine-tune recognition, the camera settings can be changed through applying new camera settings.
- position
open var position: CameraPosition { get }
Added in version 6.0.0
The direction that the camera faces.
- `default`
open class var `default`: Camera? { get }
Added in version 6.0.0
Gets the default camera of the device. This method is identical to calling init() repeatedly, first with CameraPosition.worldFacing, then with CameraPosition.userFacing followed by CameraPosition.unspecified, stopping after the first of these calls returns a non-null instance.
See init() for a more detailed description of the method behavior.
- isMacroModeAvailable
open class var isMacroModeAvailable:
Bool{ get }Added in version 6.17.0
Returns whether macro mode is available for the current device. See MacroMode for details.
- init
init?(position: CameraPosition)
Added in version 6.0.0
Retrieves the camera instance of the first camera at the provided position. In case the system does not have a camera at the provided position, null is returned.
When this method is called multiple times with the same argument, the same Camera instance is returned. The FrameSource.currentState of the camera as well as the settings depend on previous invocations. For example, if the camera is currently in use and is active, the camera’s FrameSource.currentState will be FrameSourceState.on. The only guarantee about the state and settings is that when instance is initially created, the FrameSource.currentState is FrameSourceState.off and has the default CameraSettings.
Important
In case parts of your app use custom camera settings and others use the default settings, make sure to reset the camera to use the default settings when you need them by passing the default camera settings to apply() to ensure that you don’t have any other settings when you’d expect the defaults to be active.
The camera object is returned if present, regardless whether the application has permissions to use it or not.
- init
init?(position: CameraPosition, settings: CameraSettings?)
Added in version 6.15.0
This method is identical to calling init() and then apply() consecutively.
- init
convenience init(jsonString JSONString: String) throws
Added in version 6.0.0
Constructs a new camera with the provided JSON serialization.
- `switch`
open func `switch`(toDesiredState state: FrameSourceState, completionHandler: (@Sendable (
Bool) ->Void)? = nil) ->VoidAdded in version 6.0.0
Implemented from FrameSource. See FrameSource.`switch`().
- `switch`
open func `switch`(toDesiredState state: FrameSourceState) async ->
BoolAdded in version 6.0.0
Implemented from FrameSource. See FrameSource.`switch`().
- `switch`
open func `switch`(toDesiredState state: FrameSourceState) ->
VoidAdded in version 6.0.0
Convenience method for FrameSource.`switch`(): it is the same as calling `switch`() with the second argument set to null.
- apply
open func apply(_ settings: CameraSettings, completionHandler: (@Sendable () ->
Void)? = nil) ->VoidAdded in version 6.0.0
Applies the camera settings to the camera. The task will complete when the settings have been applied and the camera has switched to use the new settings. If the camera is currently in FrameSourceState.off state, the task will complete immediately. If, on the other hand, the camera is currently in FrameSourceState.on state, the settings will be modified on the fly.
- apply
open func apply(_ settings: CameraSettings) async ->
VoidAdded in version 6.0.0
Applies the camera settings to the camera. The task will complete when the settings have been applied and the camera has switched to use the new settings. If the camera is currently in FrameSourceState.off state, the task will complete immediately. If, on the other hand, the camera is currently in FrameSourceState.on state, the settings will be modified on the fly.
- isTorchAvailable
open var isTorchAvailable:
Bool{ get }Added in version 6.0.0
Whether the torch is available for the given camera.
- desiredTorchState
open var desiredTorchState: TorchState { get, set }
Added in version 6.0.0
The desired torch state for this camera. By default, the torch state is TorchState.off. When setting the desired torch state to TorchState.on, the torch will be on as long as the camera is running (the camera’s state is FrameSourceState.on) and off otherwise.
When setting the desired torch state to TorchState.auto, the torch is turned on or off based on the available illumination.
When setting the desired torch state for a camera that does not have a torch (see isTorchAvailable), this call has no effect.
- addTorchListener
open func addTorchListener(_ listener: any TorchListener) ->
VoidAdded in version 6.3.0
Add a listener that will be called when TorchState of the camera changes.
- removeTorchListener
open func removeTorchListener(_ listener: any TorchListener) ->
VoidAdded in version 6.3.0
Remove a listener for TorchState changes.
- addMacroModeListener
open func addMacroModeListener(_ listener: any MacroModeListener) ->
VoidAdded in version 6.17.0
Add a listener that will be called when MacroMode of the camera changes.
- removeMacroModeListener
open func removeMacroModeListener(_ listener: any MacroModeListener) ->
VoidAdded in version 6.17.0
Remove a listener for MacroMode changes.
- SDCCameraPositionFromJSONString
open func SDCCameraPositionFromJSONString(_ JSONString: String, _ cameraPosition: UnsafeMutablePointer<CameraPosition>) ->
BoolAdded in version 6.1.0
- SDCTorchStateFromJSONString
open func SDCTorchStateFromJSONString(_ JSONString: String, _ torchState: UnsafeMutablePointer<TorchState>) ->
BoolAdded in version 6.1.0