Cihaz Bulmayı Durdurma
Bağlı cihazdan firmware tarafından tanımlanan bulma uyarısını durdurmasını isteyin.
Ö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
stopFindDevice 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.
public protocol DeviceFindAPI: DeviceAPI {
/// Requests that the connected device stop its locate-device indication.
/// - Parameters:
/// - completion: Called when command processing completes.
/// - success: `true` when the device accepted the stop command;
/// otherwise, `false`.
/// - error: The command or communication error, or `nil` on success.
func stopFindDevice(_ completion: AIBudsCompletionHandler?)
}/// Controls the locate-device indication on a connected device.
@protocol AIBudsDeviceFindAPI <AIBudsDeviceAPI>
/// Requests that the connected device stop its locate-device indication.
/// - Parameters:
/// - completion: Called when command processing completes.
/// - success: `true` when the device accepted the stop command;
/// otherwise, `false`.
/// - error: The command or communication error, or `nil` on success.
- (void)stopFindDeviceWithCompletion:(AIBudsCompletionHandler _Nullable)completion;
@endÖrnek Yöntemi
Bağlı cihazdan bulma uyarısını durdurmasını ister.
- Swift
- Objective-C
/// Requests that the connected device stop its locate-device indication.
/// - Parameters:
/// - completion: Called when command processing completes.
/// - success: `true` when the device accepted the stop command; otherwise,
/// `false`.
/// - error: The command or communication error, or `nil` on success.
func stopFindDevice(_ completion: AIBudsCompletionHandler?)/// Requests that the connected device stop its locate-device indication.
/// - Parameters:
/// - completion: Called when command processing completes.
/// - success: `true` when the device accepted the stop command; otherwise,
/// `false`.
/// - error: The command or communication error, or `nil` on success.
- (void)stopFindDeviceWithCompletion:(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 durdurma komutunu 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. Sonuç completion işleyicisi aracılığıyla sağlanır.
Kullanım Örnekleri
- Swift
- Objective-C
import AIBuds
final class DeviceManager {
weak var device: DeviceConvertible?
func stopFindingDevice() {
guard let device = device as? DeviceFindAPI else {
print("Device does not support finding")
return
}
device.stopFindDevice { success, error in
guard success else {
print("Failed to stop finding: \(error?.localizedDescription ?? "Unknown error")")
return
}
print("Stop 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 stopFindDeviceWithCompletion:^(BOOL success, NSError *_Nullable error) {
if (!success) {
NSLog(@"Failed to stop finding: %@", error.localizedDescription ?: @"Unknown error");
return;
}
NSLog(@"Stop command accepted");
}];Hata Yönetimi
Durdurma komutunun kabul edildiğini göstermeden önce success değerini denetleyin; komut veya iletişim hatalarında error kullanın. Hedef cihaz için belgelenmemiş sabit hata kodları varsaymayın.
En İyi Uygulamalar
- Protokol Uyumluluğunu Denetleyin: Yöntemi çağırmadan önce
DeviceFindAPIdesteğini doğrulayın. - Arayüz Durumunu Yerel Olarak İzleyin: Protokol bulma işleminin etkin olup olmadığını bildiren bir özellik sunmaz.
- Kullanıcı Arayüzünü Ana Kuyrukta Güncelleyin: Completion işleyicisindeki UIKit güncellemelerini ana kuyruğa yönlendirin.
Notlar
- Genel API, etkin bir bulma işlemi yokken durdurma çağrısının sonucunu tanımlamaz.
- Cihaza özgü bulma uyarısı bu API sözleşmesinin kapsamı dışındadır.
- Bu işlem cihaz tarafındaki uyarıyı durdurur. iPhone tarafındaki iPhone bulma uyarısını durdurmaz; bu uyarı ana uygulama tarafından yönetilir.