मुख्य कंटेंट तक स्किप करें

फ़ोटो लें

CaptureMode के साथ device photo-taking session शुरू करें और सही समय पर session बंद करें।

आवश्यक शर्तें

  • डिवाइस connected है, storage उपलब्ध है और वह DeviceCameraAPI को conform करता है।

API संदर्भ

प्रोटोकॉल

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?)
}
Methodउपयोग
requestPhotoTaking.camera या .ai mode में photo taking शुरू करें।
requestStopPhotoTakingActive photo-taking session बंद करें।

Callbacks success, optional device statusCode और optional NSError लौटाते हैं। वे photo file path नहीं लौटाते।

उपयोग के उदाहरण

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") }
}