メインコンテンツまでスキップ

デバイス探索の停止

接続中のデバイスに、ファームウェアで定義された探索通知の停止を要求します。

前提条件

この API を呼び出す前に、次の条件を確認してください。

  • デバイスが接続済みで、操作可能な状態であること
  • デバイスが DeviceFindAPI プロトコルに対応していること

API リファレンス

フレームワーク

AIBuds.xcframework

インポート

Swift
import AIBuds

プロトコル

stopFindDevice メソッドは DeviceFindAPI で定義されています。

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

インスタンスメソッド

接続中のデバイスに探索通知の停止を要求します。

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

パラメータ

パラメータ説明
completionAIBudsCompletionHandler?コマンド処理完了時に呼び出される任意のハンドラー。

コールバックのパラメータ:

名前説明
successBool / BOOLデバイスが停止コマンドを受理した場合は true、それ以外は false
errorNSError?コマンドまたは通信のエラー。成功時は nil

戻り値

このメソッドは値を直接返しません。結果は完了ハンドラーに渡されます。

使用例

Swift
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")
        }
    }
}

エラー処理

停止コマンドが受理されたと表示する前に success を確認し、コマンドまたは通信の失敗は error で処理します。対象デバイスについて文書化されていない固定エラーコードを前提にしないでください。

ベストプラクティス

  1. プロトコル対応を確認する: メソッドを呼び出す前に DeviceFindAPI への対応を確認します。
  2. UI 状態をアプリ側で管理する: このプロトコルには探索中かどうかを返すプロパティがありません。
  3. メインキューで UI を更新する: 完了ハンドラーからの UIKit 更新はメインキューへ切り替えます。

注意事項

  • 探索動作が実行されていない状態で停止を呼び出した場合の結果は、公開 API では定義されていません。
  • デバイス固有の探索通知方法は、この API の仕様には含まれません。
  • 停止するのはデバイス側の通知です。iPhone 側の「iPhone を探す」通知はホストアプリが管理するため、この API では停止しません。