iPhone’un Bulunduğunu Bildirme
Cihazdan gelen iPhone’u bulma isteğine yanıt verin, uygulamanızdaki iPhone uyarısını yönetin ve kullanıcı iPhone’u bulduktan sonra isteği gönderen cihazı bilgilendirin.
Bu akış Cihazı Bulma işleminin ters yönüdür: akışı bağlı cihaz başlatır; iPhone’u bulmak için kullanılan ses, titreşim ve kullanıcı arayüzünün yönetimi ana uygulamaya aittir.
Ön Koşullar
iPhone’un bulunduğunu bildirmeden önce şunları doğrulayın:
- İsteği gönderen cihaz bağlı ve hazır kalır.
- Uygulamanız
deviceDidRequestStartFindingPhonevedeviceDidRequestStopFindingPhoneya da bunlara karşılık gelenSDKDelegatecallback’lerini izler. - Cihaz
FindPhoneStateReportingAPIprotokolünü destekler. - Kullanıcı iPhone’u bulduğunu onayladıktan sonra uygulama iPhone tarafındaki uyarıyı durdurmuştur.
API Referansı
Framework
AIBuds.xcframework
İçe Aktarma
- Swift
- Objective-C
import AIBuds#import <AIBuds/AIBuds-Swift.h>
#import <AIBuds/AIBuds.h>Protokol
notifyPhoneFound yöntemi FindPhoneStateReportingAPI içinde tanımlanır.
- 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;
@endÖrnek Yöntemi
Bağlı cihaza kullanıcının iPhone’u bulduğunu bildirir.
- 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 Referansındaki notifyPhoneFound öğesine bakın.
Parametreler
| Parametre | Tür | Açıklama |
|---|---|---|
completion | AIBudsCompletionHandler? | Rapor iletimi ve komut işleme tamamlandığında çağrılan isteğe bağlı işleyici. |
Callback Parametreleri:
| Ad | Tür | Açıklama |
|---|---|---|
success | Bool / BOOL | Cihaz iPhone bulundu raporunu kabul ettiyse true; aksi takdirde false. |
error | NSError? | Komut ya da iletişim hatası; başarılıysa nil. |
Dönüş Değeri
Bu yöntem doğrudan değer döndürmez. Completion callback’i sonucun isteği gönderen cihaza iletildiğini bildirir; yeni bir iPhone bulma isteği başlatmaz.
Kullanım Örnekleri
Cihazdan gelen başlatma ve durdurma isteklerini izleyin. Kullanıcı iPhone’u bulduğunu onayladığında sonucu bildirmeden önce iPhone tarafındaki uyarıyı durdurun.
- 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");
}];
}Hata Yönetimi
iPhone tarafındaki uyarı durumunu rapor iletiminden bağımsız tutun. Cihaz istediğinde veya kullanıcı iPhone’u bulduğunu onayladığında uyarıyı hemen durdurun; ardından notifyPhoneFound iletişim hatasını, uyarıyı otomatik yeniden başlatmadan gösterin.
En İyi Uygulamalar
- Cihaz İsteklerine Yanıt Verin: iPhone tarafındaki uyarıyı yalnızca ilgili delegate callback’inden sonra başlatın.
- iPhone Deneyimini Uygulamada Yönetin: Ses, titreşim, izinler, arka plan davranışı ve kullanıcı arayüzünü ana uygulamada gerçekleştirin.
- Bildirmeden Önce Durdurun:
notifyPhoneFound(_:)çağırmadan önce yerel uyarı kaynaklarını durdurun. - İsteği Gönderen Cihazı Koruyun: Raporu isteği başlatan aynı bağlı cihaza gönderin.
- Kullanıcı Arayüzünü Ana Kuyrukta Güncelleyin: Delegate ve completion callback’lerindeki UIKit işlerini ana kuyruğa yönlendirin.
Notlar
notifyPhoneFound(_:)sonucun bildirildiğini onaylar; iPhone bulma işlemi başlatmaz.- Cihazdan gelen durdurma isteği, uygulamanın iPhone tarafındaki uyarıyı durdurması gerektiği anlamına gelir. Bu, kullanıcının onayladığı iPhone bulundu raporundan ayrıdır.
- Uygulamanın bağlı cihazda bulma uyarısı göstermesi gerektiğinde
DeviceFindAPIkullanın.