Ana içeriğe geç

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:

API Referansı

Framework

AIBuds.xcframework

İçe Aktarma

Swift
import AIBuds

Protokol

notifyPhoneFound yöntemi FindPhoneStateReportingAPI içinde tanımlanır.

Swift
/// 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?)
}

Örnek Yöntemi

Bağlı cihaza kullanıcının iPhone’u bulduğunu bildirir.

Swift
/// 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?)

API Referansındaki notifyPhoneFound öğesine bakın.

Parametreler

ParametreTürAçıklama
completionAIBudsCompletionHandler?Rapor iletimi ve komut işleme tamamlandığında çağrılan isteğe bağlı işleyici.

Callback Parametreleri:

AdTürAçıklama
successBool / BOOLCihaz iPhone bulundu raporunu kabul ettiyse true; aksi takdirde false.
errorNSError?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
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")
        }
    }
}

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

  1. Cihaz İsteklerine Yanıt Verin: iPhone tarafındaki uyarıyı yalnızca ilgili delegate callback’inden sonra başlatın.
  2. iPhone Deneyimini Uygulamada Yönetin: Ses, titreşim, izinler, arka plan davranışı ve kullanıcı arayüzünü ana uygulamada gerçekleştirin.
  3. Bildirmeden Önce Durdurun: notifyPhoneFound(_:) çağırmadan önce yerel uyarı kaynaklarını durdurun.
  4. İsteği Gönderen Cihazı Koruyun: Raporu isteği başlatan aynı bağlı cihaza gönderin.
  5. 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 DeviceFindAPI kullanın.