iPhone मिलने की सूचना दें
डिवाइस से आए find-iPhone अनुरोध का जवाब दें, ऐप में iPhone-side alert संभालें और उपयोगकर्ता के iPhone ढूँढ लेने पर अनुरोध करने वाले डिवाइस को सूचित करें।
यह डिवाइस ढूँढें workflow की उलटी दिशा है: इसे जुड़ा डिवाइस शुरू करता है, जबकि iPhone ढूँढने के लिए ध्वनि, vibration और UI होस्ट ऐप संभालता है।
पहले की आवश्यकताएँ
iPhone मिलने की सूचना देने से पहले सुनिश्चित करें:
- अनुरोध करने वाला डिवाइस connected और ready रहता है।
- ऐप
deviceDidRequestStartFindingPhoneऔरdeviceDidRequestStopFindingPhone, या उनकेSDKDelegatecallbacks को observe करता है। - डिवाइस
FindPhoneStateReportingAPIका समर्थन करता है। - उपयोगकर्ता के iPhone मिल जाने की पुष्टि करने के बाद ऐप ने iPhone-side indication बंद कर दिया है।
API संदर्भ
फ्रेमवर्क
AIBuds.xcframework
Import
- Swift
- Objective-C
import AIBuds#import <AIBuds/AIBuds-Swift.h>
#import <AIBuds/AIBuds.h>प्रोटोकॉल
notifyPhoneFound method, FindPhoneStateReportingAPI में परिभाषित है।
- Swift
- Objective-C
/// Reports to a connected device that its find-phone request has been resolved.
///
/// Find-phone is initiated by the device rather than by this API. Observe
/// `DeviceDelegate.deviceDidRequestStartFindingPhone(_:)` and
/// `DeviceDelegate.deviceDidRequestStopFindingPhone(_:)`, or the corresponding
/// `SDKDelegate` callbacks, to start and stop the app's phone-side alert.
///
/// After the user locates the phone, call `notifyPhoneFound(_:)` to notify the
/// requesting device. To make the connected device itself emit a locate
/// indication, use `DeviceFindAPI` instead.
public protocol FindPhoneStateReportingAPI: DeviceAPI {
/// Notifies the connected device that the user has found the phone.
///
/// Call this after handling a device-originated find-phone request and
/// stopping the phone-side alert. The completion reports delivery and
/// command processing; it does not represent a new find-phone request.
/// - Parameters:
/// - completion: Called when command processing completes.
/// - success: `true` when the device accepted the report; otherwise,
/// `false`.
/// - error: The command or communication error, or `nil` on success.
func notifyPhoneFound(_ completion: AIBudsCompletionHandler?)
}/// Reports to a connected device that its find-phone request has been resolved.
///
/// Find-phone is initiated by the device. Observe the device or SDK delegate
/// callbacks to start and stop the app's phone-side alert.
@protocol AIBudsFindPhoneStateReportingAPI <AIBudsDeviceAPI>
/// Notifies the connected device that the user has found the phone.
///
/// Call this after stopping the phone-side alert. The completion reports
/// delivery and command processing; it does not start a new request.
/// - Parameters:
/// - completion: Called when command processing completes.
/// - success: `true` when the device accepted the report; otherwise,
/// `false`.
/// - error: The command or communication error, or `nil` on success.
- (void)notifyPhoneFoundWithCompletion:(AIBudsCompletionHandler _Nullable)completion;
@endInstance method
जुड़े डिवाइस को बताता है कि उपयोगकर्ता ने iPhone ढूँढ लिया है।
- Swift
- Objective-C
/// Notifies the connected device that the user has found the phone.
///
/// Call this after handling a device-originated find-phone request and
/// stopping the phone-side alert. The completion reports delivery and
/// command processing; it does not represent a new find-phone request.
/// - Parameters:
/// - completion: Called when command processing completes.
/// - success: `true` when the device accepted the report; otherwise,
/// `false`.
/// - error: The command or communication error, or `nil` on success.
func notifyPhoneFound(_ completion: AIBudsCompletionHandler?)/// Notifies the connected device that the user has found the phone.
///
/// Call this after stopping the phone-side alert. The completion reports
/// delivery and command processing; it does not start a new request.
/// - Parameters:
/// - completion: Called when command processing completes.
/// - success: `true` when the device accepted the report; otherwise,
/// `false`.
/// - error: The command or communication error, or `nil` on success.
- (void)notifyPhoneFoundWithCompletion:(AIBudsCompletionHandler _Nullable)completion;API संदर्भ में notifyPhoneFound देखें।
पैरामीटर
| पैरामीटर | प्रकार | विवरण |
|---|---|---|
completion | AIBudsCompletionHandler? | Report delivery और command processing पूरा होने पर call होने वाला optional handler। |
Callback पैरामीटर:
| नाम | प्रकार | विवरण |
|---|---|---|
success | Bool / BOOL | डिवाइस ने iPhone-found report स्वीकार किया हो तो true, अन्यथा false। |
error | NSError? | Command या communication error; सफल होने पर nil। |
Return value
यह method सीधे कोई value return नहीं करता। इसका completion अनुरोध करने वाले डिवाइस तक परिणाम पहुँचने की सूचना देता है; नया find-iPhone अनुरोध शुरू नहीं करता।
उपयोग के उदाहरण
डिवाइस से आने वाले start और stop requests observe करें। उपयोगकर्ता के iPhone मिल जाने की पुष्टि करने पर परिणाम बताने से पहले iPhone-side alert बंद करें।
- Swift
- Objective-C
import AIBuds
final class FindPhoneCoordinator: NSObject, DeviceDelegate {
private weak var requestingDevice: DeviceConvertible?
func deviceDidRequestStartFindingPhone(_ device: DeviceConvertible) {
requestingDevice = device
DispatchQueue.main.async {
self.startPhoneAlert()
}
}
func deviceDidRequestStopFindingPhone(_ device: DeviceConvertible) {
DispatchQueue.main.async {
self.stopPhoneAlert()
}
}
func userConfirmedPhoneFound() {
stopPhoneAlert()
guard let reporter = requestingDevice as? FindPhoneStateReportingAPI else {
print("Device cannot receive a phone-found report")
return
}
reporter.notifyPhoneFound { success, error in
guard success else {
print(
"Failed to report phone found: \(error?.localizedDescription ?? "Unknown error")"
)
return
}
print("Phone-found report accepted")
}
}
}#import <AIBuds/AIBuds-Swift.h>
#import <AIBuds/AIBuds.h>
@property(nonatomic, weak) id<AIBudsDeviceConvertible> requestingDevice;
- (void)deviceDidRequestStartFindingPhone:(id<AIBudsDeviceConvertible>)device {
self.requestingDevice = device;
dispatch_async(dispatch_get_main_queue(), ^{
[self startPhoneAlert];
});
}
- (void)deviceDidRequestStopFindingPhone:(id<AIBudsDeviceConvertible>)device {
dispatch_async(dispatch_get_main_queue(), ^{
[self stopPhoneAlert];
});
}
- (void)userConfirmedPhoneFound {
[self stopPhoneAlert];
id<AIBudsFindPhoneStateReportingAPI> reporter =
(id<AIBudsFindPhoneStateReportingAPI>)self.requestingDevice;
if (![reporter conformsToProtocol:@protocol(AIBudsFindPhoneStateReportingAPI)]) {
NSLog(@"Device cannot receive a phone-found report");
return;
}
[reporter notifyPhoneFoundWithCompletion:^(BOOL success, NSError *_Nullable error) {
if (!success) {
NSLog(@"Failed to report phone found: %@",
error.localizedDescription ?: @"Unknown error");
return;
}
NSLog(@"Phone-found report accepted");
}];
}Error handling
iPhone-side alert state को report delivery से अलग रखें। डिवाइस के कहने या उपयोगकर्ता के iPhone मिल जाने की पुष्टि करने पर alert तुरंत बंद करें; फिर notifyPhoneFound communication error दिखाएँ, लेकिन alert अपने-आप दोबारा शुरू न करें।
बेहतर तरीके
- डिवाइस अनुरोध पर प्रतिक्रिया दें: संबंधित delegate callback मिलने के बाद ही iPhone-side indication शुरू करें।
- iPhone अनुभव ऐप में संभालें: ध्वनि, vibration, permissions, background behavior और UI होस्ट ऐप में लागू करें।
- सूचना देने से पहले रोकें:
notifyPhoneFound(_:)call करने से पहले local alert resources बंद करें। - अनुरोध करने वाला डिवाइस बनाए रखें: Report उसी जुड़े डिवाइस को भेजें जिसने अनुरोध शुरू किया था।
- UI को main queue पर अपडेट करें: Delegate और completion callbacks से UIKit work main queue पर भेजें।
ध्यान देने योग्य बातें
notifyPhoneFound(_:)परिणाम की पुष्टि करता है; find-iPhone operation शुरू नहीं करता।- डिवाइस से आया stop request ऐप को iPhone-side indication बंद करने को कहता है। यह उपयोगकर्ता द्वारा पुष्टि किए गए iPhone-found report से अलग है।
- जब ऐप को जुड़े डिवाइस पर locate indication दिखाना हो तब
DeviceFindAPIउपयोग करें।