简体   繁体   中英

How to know if a Bluetooth Device is Connected in iOS?

What is the best way to know on how a Bluetooth Device is already connected? I am using CBCentralManager to identify if the Bluetooth is Powered ON but I am unable to find out on how I can identify If a Bluetooth Device is already connected.

I am implementing routing of AVAudioSession Calls via a Connected Bluetooth device but AudioSession Category changes are getting called repeatedly due to which I am unable to find if a Bluetooth Device is connected or not. If anyone have tried to implement this behaviour, Your inputs might be helpful. Please share the information.

I am using CBPeripheral.state ==.connected to check the state of the BLE device.

From the documentation:

/**
 *  @enum CBPeripheralState
 *
 *  @discussion Represents the current connection state of a CBPeripheral.
 *
 */
@available(iOS 7.0, *)
public enum CBPeripheralState : Int {

    
    case disconnected = 0

    case connecting = 1

    case connected = 2

    @available(iOS 9.0, *)
    case disconnecting = 3
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM