Skip to main content

Find Device

Request that a connected device start its firmware-defined locate-device indication. This API locates the represented device; it does not scan for nearby Bluetooth devices.

Prerequisites

Before calling this API, ensure:

  • The device is connected and ready
  • The device supports the DeviceFindAPI protocol

API Reference

Framework

AIBuds.xcframework

Import

Swift
import AIBuds

Protocol

The findDevice method is defined in 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. 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?)
}

Instance Method

Requests that the connected device start its locate-device indication.

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

Parameters

ParameterTypeDescription
completionAIBudsCompletionHandler?Optional handler called when command processing completes.

Callback Parameters:

NameTypeDescription
successBool / BOOLtrue when the device accepted the command; otherwise false.
errorNSError?The command or communication error, or nil on success.

Return Value

This method does not return a value directly. Its completion reports command processing, not whether the user has physically located the device.

Usage Examples

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

Observe the Device-Found Event

When supported by the device, deviceDidReportFound is the distinct, device-originated terminal event:

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

Error Handling

Check success before showing that the command was accepted, and use error for command or communication failures. Do not present successful command processing as “device found”; wait for the separate found event when the device supports it.

Best Practices

  1. Check Protocol Conformance: Verify DeviceFindAPI support before calling the method.
  2. Use Precise UI State: Distinguish “command accepted” from “device found.”
  3. Provide a Stop Action: Make stopFindDevice(_:) available after starting the indication.
  4. Observe the Found Event: Implement the device or SDK delegate callback when supported.
  5. Update UI on the Main Queue: Dispatch UIKit updates from completions and delegate callbacks to the main queue.

Notes

  • This API controls an already-connected device and does not discover or scan for devices.
  • The public API defines a locate indication but does not prescribe how a device presents it.
  • Sound, vibration, duration, and volume behavior can be device-specific.
  • Find-iPhone is the opposite direction; see Report iPhone Found.