TWS कनेक्शन की स्थिति देखें
जाँचें कि TWS डिवाइस इस समय connected है या नहीं।
आवश्यक शर्तें
- डिवाइस
DeviceTWSAPIको conform करता है। - UI में device type और connection state अलग दिखाने के लिए
isTwsउपयोग करें।
API संदर्भ
Framework
AIBuds.xcframework
Import
- Swift
- Objective-C
import AIBuds#import <AIBuds/AIBuds-Swift.h>
#import <AIBuds/AIBuds.h>प्रोटोकॉल
Connection state 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;
@endप्रॉपर्टी
| Property | Type | विवरण |
|---|---|---|
isTwsConnected | Bool / BOOL | वर्तमान TWS connection snapshot। |
उपयोग के उदाहरण
- 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");
}त्रुटि प्रबंधन
यह property error नहीं लौटाती। इसे किसी एक समय का snapshot मानें और unsupported protocol conformance को अलग संभालें।
श्रेष्ठ अभ्यास
- बदलाव देखें: Live indicator के लिए
didTwsConnectionStatusChangedimplement करें। - Connection command न मानें: यह protocol pairing या reconnection शुरू नहीं करता।
- UI सुरक्षित रूप से अपडेट करें: जरूरत होने पर delegate से आने वाला UI work main queue पर dispatch करें।
ध्यान दें
falseका अर्थ है कि वर्तमान TWS connection active नहीं है; इससे अकेले यह साबित नहीं होता कि डिवाइस TWS नहीं है।- SDK Demo इस property को सीधे दिखाता है और device delegate से इसे update करता है।