Cihazı Bulma
Bağlı cihazdan firmware tarafından tanımlanan bulma uyarısını başlatmasını isteyin. Bu API temsil edilen cihazı bulmaya yarar; yakındaki Bluetooth cihazlarını taramaz.
Ön Koşullar
Bu API’yi çağırmadan önce şunları doğrulayın:
- Cihaz bağlı ve hazırdır
- Cihaz
DeviceFindAPIprotokolünü destekler
API Referansı
Framework
AIBuds.xcframework
İçe Aktarma
- Swift
- Objective-C
import AIBuds#import <AIBuds/AIBuds-Swift.h>
#import <AIBuds/AIBuds.h>Protokol
findDevice yöntemi DeviceFindAPI içinde tanımlanır.
- Swift
- Objective-C
/// Controls the locate-device indication on a connected device.
///
/// This API operates on the device represented by the conforming object. It
/// does not perform Bluetooth discovery or scan for nearby devices. The
/// indication used to locate the device, such as sound, vibration, or another
/// firmware-defined behavior, depends on the device implementation.
///
/// A successful completion from `findDevice(_:)` means the start command was
/// accepted; it does not mean the device has been physically located. Observe
/// `DeviceDelegate.deviceDidReportFound(_:)` or
/// `SDKDelegate.deviceDidReportFound(_:)` when the device supports reporting
/// that it has been found.
public protocol DeviceFindAPI: DeviceAPI {
/// Requests that the connected device start its locate-device indication.
///
/// The completion reports whether the command was accepted and executed by
/// the device. It does not report whether the user has located the device.
/// Use `DeviceDelegate.deviceDidReportFound(_:)` or the corresponding
/// `SDKDelegate` callback for a device-originated found event.
/// - Parameters:
/// - completion: Called when command processing completes.
/// - success: `true` when the device accepted the command; otherwise,
/// `false`.
/// - error: The command or communication error, or `nil` on success.
func findDevice(_ completion: AIBudsCompletionHandler?)
}/// Controls the locate-device indication on a connected device.
///
/// This API operates on the device represented by the conforming object. It
/// does not perform Bluetooth discovery or scan for nearby devices. A
/// successful completion means command acceptance, not physical location.
@protocol AIBudsDeviceFindAPI <AIBudsDeviceAPI>
/// Requests that the connected device start its locate-device indication.
///
/// The completion reports command processing. A supported device reports
/// the terminal found event separately through the device or SDK delegate.
/// - Parameters:
/// - completion: Called when command processing completes.
/// - success: `true` when the device accepted the command; otherwise,
/// `false`.
/// - error: The command or communication error, or `nil` on success.
- (void)findDeviceWithCompletion:(AIBudsCompletionHandler _Nullable)completion;
@endÖrnek Yöntemi
Bağlı cihazdan bulma uyarısını başlatmasını ister.
- Swift
- Objective-C
/// Requests that the connected device start its locate-device indication.
///
/// The completion reports whether the command was accepted and executed by
/// the device. It does not report whether the user has located the device.
/// Use `DeviceDelegate.deviceDidReportFound(_:)` or the corresponding
/// `SDKDelegate` callback for a device-originated found event.
/// - Parameters:
/// - completion: Called when command processing completes.
/// - success: `true` when the device accepted the command; otherwise,
/// `false`.
/// - error: The command or communication error, or `nil` on success.
func findDevice(_ completion: AIBudsCompletionHandler?)/// Requests that the connected device start its locate-device indication.
///
/// The completion reports command processing. A supported device reports the
/// terminal found event separately through the device or SDK delegate.
/// - Parameters:
/// - completion: Called when command processing completes.
/// - success: `true` when the device accepted the command; otherwise,
/// `false`.
/// - error: The command or communication error, or `nil` on success.
- (void)findDeviceWithCompletion:(AIBudsCompletionHandler _Nullable)completion;Parametreler
| Parametre | Tür | Açıklama |
|---|---|---|
completion | AIBudsCompletionHandler? | 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 komutu 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 komutun işlenmesini bildirir; kullanıcının cihazı fiziksel olarak bulup bulmadığını bildirmez.
Kullanım Örnekleri
- Swift
- Objective-C
import AIBuds
final class DeviceManager {
weak var device: DeviceConvertible?
func startFindingDevice() {
guard let device = device as? DeviceFindAPI else {
print("Device does not support finding")
return
}
device.findDevice { success, error in
guard success else {
print("Failed to start finding: \(error?.localizedDescription ?? "Unknown error")")
return
}
print("Locate-device command accepted")
}
}
}#import <AIBuds/AIBuds-Swift.h>
#import <AIBuds/AIBuds.h>
id<AIBudsDeviceFindAPI> device = (id<AIBudsDeviceFindAPI>)self.device;
if (![device conformsToProtocol:@protocol(AIBudsDeviceFindAPI)]) {
NSLog(@"Device does not support finding");
return;
}
[device findDeviceWithCompletion:^(BOOL success, NSError *_Nullable error) {
if (!success) {
NSLog(@"Failed to start finding: %@", error.localizedDescription ?: @"Unknown error");
return;
}
NSLog(@"Locate-device command accepted");
}];Cihaz Bulundu Olayını İzleme
Cihaz destekliyorsa deviceDidReportFound, cihaz tarafından gönderilen ayrı bitiş olayıdır:
- Swift
- Objective-C
/// Called when the device reports that it has been found.
///
/// This is distinct from `findDevice(_:)` completion, which only reports
/// command processing.
func deviceDidReportFound(_ device: DeviceConvertible) {
DispatchQueue.main.async {
self.showDeviceFoundState()
}
}/// Called when the device reports that it has been found.
///
/// This is distinct from the find command completion, which only reports
/// command processing.
- (void)deviceDidReportFound:(id<AIBudsDeviceConvertible>)device {
dispatch_async(dispatch_get_main_queue(), ^{
[self showDeviceFoundState];
});
}Hata Yönetimi
Komutun kabul edildiğini göstermeden önce success değerini denetleyin; komut veya iletişim hatalarında error kullanın. Başarılı komut işlemeyi “cihaz bulundu” olarak göstermeyin; cihaz destekliyorsa ayrı bulundu olayını bekleyin.
En İyi Uygulamalar
- Protokol Uyumluluğunu Denetleyin: Yöntemi çağırmadan önce
DeviceFindAPIdesteğini doğrulayın. - Kesin Arayüz Durumu Kullanın: “Komut kabul edildi” ile “cihaz bulundu” durumlarını ayırın.
- Durdurma Eylemi Sunun: Uyarıyı başlattıktan sonra
stopFindDevice(_:)seçeneğini kullanılabilir yapın. - Bulundu Olayını İzleyin: Desteklendiğinde cihaz veya SDK delegate callback’ini uygulayın.
- Kullanıcı Arayüzünü Ana Kuyrukta Güncelleyin: Completion ve delegate callback’lerindeki UIKit güncellemelerini ana kuyruğa yönlendirin.
Notlar
- Bu API zaten bağlı olan cihazı denetler; cihaz keşfi veya taraması yapmaz.
- Genel API bulma uyarısını tanımlar, ancak cihazın bunu nasıl sunacağını belirlemez.
- Ses, titreşim, süre ve ses düzeyi davranışı cihaza özgü olabilir.
- iPhone’u bulma ters yöndeki akıştır; iPhone’un Bulunduğunu Bildirme sayfasına bakın.