Skip to main content

Take Photos

Start a device photo-taking session with a CaptureMode, then stop the session when appropriate.

Prerequisites​

  • The device is connected and conforms to DeviceCameraAPI. Devices without onboard storage can push the captured JPEG directly to the app.

API Reference​

Protocol​

Swift
/// The protocol for device API that supports camera.
protocol DeviceCameraAPI: DeviceAPI {
    /// Requests to take a photo with the specified capture mode.
    /// - Parameters:
    ///   - mode: The capture mode for photo taking.
    ///   - completion: A closure that is called when the operation completes.
    ///     - success: `true` if the operation was successful; otherwise `false`.
    ///     - statusCode: The status code returned by the device. `nil` if the operation failed.
    ///     - error: An `NSError` object that describes the error that occurred, or `nil` if the operation was successful.
    func requestPhotoTaking(
        withCaptureMode mode: CaptureMode,
        completion: AIBudsStatusCodeCompletionHandler?
    )

    /// Requests to stop the current photo taking session.
    /// - Parameters:
    ///   - completion: A closure that is called when the operation completes.
    ///     - success: `true` if the operation was successful; otherwise `false`.
    ///     - statusCode: The status code returned by the device. `nil` if the operation failed.
    ///     - error: An `NSError` object that describes the error that occurred, or `nil` if the operation was successful.
    func requestStopPhotoTaking(_ completion: AIBudsStatusCodeCompletionHandler?)
}
MethodPurpose
requestPhotoTakingStart photo taking in .camera or .ai mode.
requestStopPhotoTakingStop the active photo-taking session.

The request callbacks return success, an optional device statusCode, and an optional NSError. They do not return a photo file path.

Instant Photo Callback​

Storage-less glasses deliver the captured JPEG through the optional device(_:didReceiveInstantPhotoData:error:) callback. Implement it on either DeviceDelegate or SDKDelegate; handle error first and treat a missing or empty photoData value as a failed transfer.

Swift
func device(
    _ device: DeviceConvertible,
    didReceiveInstantPhotoData photoData: Data?,
    error: NSError?
) {
    guard error == nil, let photoData, !photoData.isEmpty else { return }
    // Decode or persist the JPEG away from the callback path.
}

The SDK invokes this callback for supported storage-less glasses after capture. Do not wait for it on devices that save photos to onboard storage, and dispatch UI or Photos-library work to the appropriate queue.

Usage Examples​

Swift
guard let device = device as? DeviceCameraAPI else { return }

device.requestPhotoTaking(withCaptureMode: .camera) { success, statusCode, error in
    guard success else {
        print(error?.localizedDescription ?? "Photo request failed")
        return
    }
    print("Photo taking started: \(statusCode?.stringValue ?? "Unavailable")")
}

device.requestStopPhotoTaking { success, _, error in
    if !success { print(error?.localizedDescription ?? "Stop failed") }
}