사진 촬영
CaptureMode로 기기 사진 촬영 세션을 시작하고 필요한 시점에 세션을 중지합니다.
사전 요구 사항
- 기기가 연결되어 있고
DeviceCameraAPI를 준수합니다. 내장 저장 공간이 없는 기기는 촬영한 JPEG를 앱으로 직접 전송할 수 있습니다.
API 참고
프로토콜
- Swift
- Objective-C
/// 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?)
}/// The protocol for device API that supports camera.
@protocol AIBudsDeviceCameraAPI <AIBudsDeviceAPI>
/// 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.
- (void)requestPhotoTakingWithCaptureMode:(enum AIBudsCaptureMode)mode
completion:(AIBudsStatusCodeCompletionHandler _Nullable)completion;
/// 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.
- (void)requestStopPhotoTakingWithCompletion:
(AIBudsStatusCodeCompletionHandler _Nullable)completion;
@end| 메서드 | 용도 |
|---|---|
requestPhotoTaking | .camera 또는 .ai 모드로 사진 촬영을 시작합니다. |
requestStopPhotoTaking | 실행 중인 사진 촬영 세션을 중지합니다. |
요청 콜백은 success, 선택적 기기 statusCode 및 선택적 NSError를 반환합니다. 사진 파일 경로는 반환하지 않습니다.
즉석 사진 콜백
내장 저장 공간이 없는 안경은 선택 사항인 device(_:didReceiveInstantPhotoData:error:) 콜백을 통해 촬영한 JPEG를 전달합니다. DeviceDelegate 또는 SDKDelegate 중 하나에서 구현하세요. 먼저 error를 확인하고 photoData가 없거나 비어 있으면 전송 실패로 처리합니다.
- Swift
- Objective-C
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.
}- (void)device:(id<AIBudsDeviceConvertible>)device
didReceiveInstantPhotoData:(NSData *_Nullable)photoData
error:(NSError *_Nullable)error {
if (error || photoData.length == 0)
return;
// Decode or persist the JPEG away from the callback path.
}이 기능을 지원하는 내장 저장 공간 없는 안경에서는 촬영 후 SDK가 이 콜백을 호출합니다. 사진을 내장 저장 공간에 저장하는 기기에서는 이 콜백을 기다리지 마세요. UI 또는 사진 보관함 관련 작업은 적절한 큐에서 실행합니다.
사용 예제
- Swift
- Objective-C
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") }
}id<AIBudsDeviceCameraAPI> device = (id<AIBudsDeviceCameraAPI>)self.device;
if ([device conformsToProtocol:@protocol(AIBudsDeviceCameraAPI)]) {
[device requestPhotoTakingWithCaptureMode:AIBudsCaptureModeCamera
completion:^(BOOL success,
NSNumber *_Nullable statusCode,
NSError *_Nullable error) {
if (!success)
NSLog(@"Photo request failed: %@",
error.localizedDescription);
}];
[device requestStopPhotoTakingWithCompletion:^(
BOOL success, NSNumber *_Nullable statusCode, NSError *_Nullable error) {
if (!success)
NSLog(@"Stop failed: %@", error.localizedDescription);
}];
}