View TWS Connection State
Read whether the TWS device is currently connected.
Prerequisites
- The device conforms to
DeviceTWSAPI. - Use
isTwswhen the UI must distinguish device type from connection state.
API Reference
Framework
AIBuds.xcframework
Import
- Swift
- Objective-C
import AIBuds#import <AIBuds/AIBuds-Swift.h>
#import <AIBuds/AIBuds.h>Protocol
The connection state is exposed by DeviceTWSAPI.
- Swift
- Objective-C
/// 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 }
}/// The protocol for device True Wireless Stereo (TWS) related API.
@protocol AIBudsDeviceTWSAPI <AIBudsDeviceAPI>
/// Indicates whether the TWS device is currently connected.
@property(nonatomic, readonly) BOOL isTwsConnected;
@endProperties
| Property | Type | Description |
|---|---|---|
isTwsConnected | Bool / BOOL | The current TWS connection snapshot. |
Usage Examples
- Swift
- Objective-C
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")id<AIBudsDeviceTWSAPI> device = (id<AIBudsDeviceTWSAPI>)self.device;
if ([device conformsToProtocol:@protocol(AIBudsDeviceTWSAPI)] && device.isTws) {
NSLog(@"%@", 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
- Observe Changes: Implement
didTwsConnectionStatusChangedfor a live indicator. - Avoid Connection Commands: This protocol does not initiate pairing or reconnection.
- Update UI Safely: Dispatch delegate-driven UI work to the main queue when required.
Notes
falsemeans 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.