रिमोट शटर संभालें
DeviceDelegate से remote-shutter events प्राप्त करें, संबंधित app-camera action चलाएँ और परिणाम को डिवाइस के साथ synchronize करें।
आवश्यकताएँ
- डिवाइस कनेक्टेड है और
DeviceRemoteShutterAPIके अनुरूप है। - app में
NSCameraUsageDescriptionentry मौजूद है और वह camera authorization माँगता है। - app अपना
AVCaptureSessionऔर photo-capture implementation संभालता है।
AI की सहायता से लागू करें
AI से बनाएँ
इस वर्कफ़्लो को AI से लागू करें
आधिकारिक “AIBuds रिमोट शटर लागू करें” स्किल से वर्कफ़्लो को अपने ऐप के अनुसार लागू करें।
https://docs-aibuds.github.io/hi/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 Callback विवरण
- 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 event flow साफ़ रखने के लिए उदाहरण app-camera की details को local methods में रखता है।
- 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;
}
}त्रुटि प्रबंधन
Permission न मिलने, storage उपलब्ध न होने या app camera के capture न कर पाने पर .photoFailed रिपोर्ट करें। App photo mode में प्रवेश न कर पाए या उससे बाहर निकल चुका हो, तो .exitedOrUnableToEnter रिपोर्ट करें।