원격 셔터 처리
DeviceDelegate에서 원격 셔터 이벤트를 받고 해당 앱 카메라 동작을 수행한 뒤 결과를 기기에 동기화합니다.
사전 요구 사항
- 기기가 연결되어 있고
DeviceRemoteShutterAPI를 준수합니다. - 앱에
NSCameraUsageDescription항목이 있고 카메라 권한을 요청합니다. - 앱에서
AVCaptureSession과 사진 촬영 기능을 구현합니다.
AI를 활용해 구현
AI로 구현
AI로 이 워크플로 구현
공식 “AIBuds 원격 셔터 구현” 스킬을 사용해 앱에 맞게 구현하세요.
https://docs-aibuds.github.io/ko/skills/implement-aibuds-remote-shutter을 읽고 지침을 따르세요. 이 스킬로 “AIBuds 원격 셔터 구현”을 이 iOS 프로젝트에 구현하고 검증하세요.API 참고
프로토콜
- Swift
- Objective-C
/// The protocol for device remote shutter API.
protocol DeviceRemoteShutterAPI: DeviceAPI {
/// Syncs the app’s real-time remote-shutter response state to the device after the device triggers remote shutter.
/// - Parameters:
/// - state: The real-time remote-shutter response state to sync to the device.
/// - completion: A closure that is called when the operation completes.
/// - success: `true` if the operation was successful; otherwise `false`.
/// - error: An `NSError` object that describes the error that occurred, or `nil` if the operation was successful.
func syncRemoteShutterStateToDevice(
_ state: RemoteShutterState,
completion: AIBudsCompletionHandler?
)
}/// The protocol for device remote shutter API.
@protocol AIBudsDeviceRemoteShutterAPI <AIBudsDeviceAPI>
/// Syncs the app’s real-time remote-shutter response state to the device after the device triggers
/// remote shutter.
/// - Parameters:
/// - state: The real-time remote-shutter response state to sync to the device.
/// - completion: A closure that is called when the operation completes.
/// - success: `true` if the operation was successful; otherwise `false`.
/// - error: An `NSError` object that describes the error that occurred, or `nil` if the
/// operation was successful.
- (void)syncRemoteShutterStateToDevice:(enum AIBudsRemoteShutterState)state
completion:(AIBudsCompletionHandler _Nullable)completion;
@endAPI 참고에서 syncRemoteShutterStateToDevice를 확인하세요.
Delegate 콜백
- Swift
- Objective-C
/// Callback when remote shutter event received
/// - Parameters:
/// - device: the device
/// - event: the remote shutter event
optional func device(
_ device: DeviceConvertible,
didReceiveRemoteShutterEvent event: RemoteShutterEvent
)/// Callback when remote shutter event received
/// - Parameters:
/// - device: the device
/// - event: the remote shutter event
- (void)device:(id<AIBudsDeviceConvertible> _Nonnull)device
didReceiveRemoteShutterEvent:(enum AIBudsRemoteShutterEvent)event;사용 예제
예제에서는 SDK 이벤트 흐름을 명확히 보여 주기 위해 앱 카메라의 세부 구현을 로컬 메서드로 분리합니다.
- Swift
- Objective-C
func device(
_ device: DeviceConvertible,
didReceiveRemoteShutterEvent event: RemoteShutterEvent
) {
guard let remoteShutter = device as? DeviceRemoteShutterAPI else { return }
switch event {
case .enter:
prepareAppCamera { ready in
let state: RemoteShutterState =
ready
? .enteredPhotoMode
: .exitedOrUnableToEnter
remoteShutter.syncRemoteShutterStateToDevice(state, completion: nil)
}
case .capture:
captureAppPhoto { success in
remoteShutter.syncRemoteShutterStateToDevice(
success ? .photoSuccess : .photoFailed,
completion: nil
)
}
case .exit:
stopAppCamera()
remoteShutter.syncRemoteShutterStateToDevice(
.exitedOrUnableToEnter,
completion: nil
)
case .unknown:
break
}
}- (void)device:(id<AIBudsDeviceConvertible>)device
didReceiveRemoteShutterEvent:(AIBudsRemoteShutterEvent)event {
id<AIBudsDeviceRemoteShutterAPI> remoteShutter = (id<AIBudsDeviceRemoteShutterAPI>)device;
if (![remoteShutter conformsToProtocol:@protocol(AIBudsDeviceRemoteShutterAPI)])
return;
switch (event) {
case AIBudsRemoteShutterEventEnter:
[self prepareAppCameraWithCompletion:^(BOOL ready) {
AIBudsRemoteShutterState state = ready ? AIBudsRemoteShutterStateEnteredPhotoMode
: AIBudsRemoteShutterStateExitedOrUnableToEnter;
[remoteShutter syncRemoteShutterStateToDevice:state completion:nil];
}];
break;
case AIBudsRemoteShutterEventCapture:
[self captureAppPhotoWithCompletion:^(BOOL success) {
AIBudsRemoteShutterState state = success ? AIBudsRemoteShutterStatePhotoSuccess
: AIBudsRemoteShutterStatePhotoFailed;
[remoteShutter syncRemoteShutterStateToDevice:state completion:nil];
}];
break;
case AIBudsRemoteShutterEventExit:
[self stopAppCamera];
[remoteShutter syncRemoteShutterStateToDevice:AIBudsRemoteShutterStateExitedOrUnableToEnter
completion:nil];
break;
default:
break;
}
}오류 처리
권한 거부, 저장 공간 부족 또는 앱 카메라 오류로 촬영하지 못하면 .photoFailed를 보고하세요. 앱이 사진 모드로 진입하지 못했거나 사진 모드를 종료했으면 .exitedOrUnableToEnter를 보고하세요.