Skip to main content

View TWS Connection State

Read whether the TWS device is currently connected.

Prerequisites

  • The device conforms to DeviceTWSAPI.
  • Use isTws when the UI must distinguish device type from connection state.

API Reference

Framework

AIBuds.xcframework

Import

Swift
import AIBuds

Protocol

The connection state is exposed by DeviceTWSAPI.

Swift
/// The protocol for device True Wireless Stereo (TWS) related API.
protocol DeviceTWSAPI: DeviceAPI {
    /// Indicates whether the TWS device is currently connected.
    var isTwsConnected: Bool { get }
}

Properties

PropertyTypeDescription
isTwsConnectedBool / BOOLThe current TWS connection snapshot.

Usage Examples

Swift
import AIBuds

guard let device = device as? DeviceTWSAPI else {
    print("TWS information is unavailable")
    return
}

guard device.isTws else {
    print("This is not a TWS device")
    return
}

print(device.isTwsConnected ? "TWS connected" : "TWS disconnected")

Error Handling

This property does not return an error. Treat it as a point-in-time snapshot and handle unsupported protocol conformance independently.

Best Practices

  1. Observe Changes: Implement didTwsConnectionStatusChanged for a live indicator.
  2. Avoid Connection Commands: This protocol does not initiate pairing or reconnection.
  3. Update UI Safely: Dispatch delegate-driven UI work to the main queue when required.

Notes

  • false means the current TWS connection is not active; it does not by itself mean the device is not a TWS device.
  • The SDK Demo displays this property directly and updates it through the device delegate.