Skip to content

Core Tws Get Connection Status

Mr.P edited this page Aug 29, 2026 · 2 revisions

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

Objective-C

#import <AIBuds/AIBuds-Swift.h>
#import <AIBuds/AIBuds.h>

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 }
}

Objective-C

/// 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;
@end

Properties

Property Type Description
isTwsConnected Bool / BOOL The 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")

Objective-C

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

  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.

AIBuds SDK iOS Wiki

Clone this wiki locally