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
DeviceFindAPIprotocol
API Reference
Framework
AIBuds.xcframework
Import
- Swift
- Objective-C
import AIBuds#import <AIBuds/AIBuds-Swift.h>
#import <AIBuds/AIBuds.h>Protocol
The findDevice method is defined in 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. 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;
@endInstance Method
Requests that the connected device start its locate-device indication.
- 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;Parameters
| Parameter | Type | Description |
|---|---|---|
completion | AIBudsCompletionHandler? | Optional handler called when command processing completes. |
Callback Parameters:
| Name | Type | Description |
|---|---|---|
success | Bool / BOOL | true when the device accepted the command; otherwise false. |
error | NSError? | 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
- 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");
}];Observe the Device-Found Event
When supported by the device, deviceDidReportFound is the distinct, device-originated terminal event:
- 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];
});
}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
- Check Protocol Conformance: Verify
DeviceFindAPIsupport before calling the method. - Use Precise UI State: Distinguish “command accepted” from “device found.”
- Provide a Stop Action: Make
stopFindDevice(_:)available after starting the indication. - Observe the Found Event: Implement the device or SDK delegate callback when supported.
- 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.