デバイス探索の停止
接続中のデバイスに、ファームウェアで定義された探索通知の停止を要求します。
前提条件
この API を呼び出す前に、次の条件を確認してください。
- デバイスが接続済みで、操作可能な状態であること
- デバイスが
DeviceFindAPIプロトコルに対応していること
API リファレンス
フレームワーク
AIBuds.xcframework
インポート
- Swift
- Objective-C
import AIBuds#import <AIBuds/AIBuds-Swift.h>
#import <AIBuds/AIBuds.h>プロトコル
stopFindDevice メソッドは DeviceFindAPI で定義されています。
- 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インスタンスメソッド
接続中のデバイスに探索通知の停止を要求します。
- 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;パラメータ
| パラメータ | 型 | 説明 |
|---|---|---|
completion | AIBudsCompletionHandler? | コマンド処理完了時に呼び出される任意のハンドラー。 |
コールバックのパラメータ:
| 名前 | 型 | 説明 |
|---|---|---|
success | Bool / BOOL | デバイスが停止コマンドを受理した場合は true、それ以外は false。 |
error | NSError? | コマンドまたは通信のエラー。成功時は nil。 |
戻り値
このメソッドは値を直接返しません。結果は完了ハンドラーに渡されます。
使用例
- 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");
}];エラー処理
停止コマンドが受理されたと表示する前に success を確認し、コマンドまたは通信の失敗は error で処理します。対象デバイスについて文書化されていない固定エラーコードを前提にしないでください。
ベストプラクティス
- プロトコル対応を確認する: メソッドを呼び出す前に
DeviceFindAPIへの対応を確認します。 - UI 状態をアプリ側で管理する: このプロトコルには探索中かどうかを返すプロパティがありません。
- メインキューで UI を更新する: 完了ハンドラーからの UIKit 更新はメインキューへ切り替えます。
注意事項
- 探索動作が実行されていない状態で停止を呼び出した場合の結果は、公開 API では定義されていません。
- デバイス固有の探索通知方法は、この API の仕様には含まれません。
- 停止するのはデバイス側の通知です。iPhone 側の「iPhone を探す」通知はホストアプリが管理するため、この API では停止しません。