问题
From iOS 13 it should be possibile to register for connection events of BR/EDR Bluetooth (Classic) devices. I have followed the instructions provided in the WWDC keynote, in particular I init my CBCentralManager in this way:
func initCentralManager() {
if self.centralManager == nil{
self.centralManager = CBCentralManager.init(delegate: self, queue: nil, options:[CBCentralManagerOptionRestoreIdentifierKey:"myCentralManagerIdentifier"]);
if #available(iOS 13.0, *) {
let matchingOptions = [CBConnectionEventMatchingOption.serviceUUIDs:[CBUUID(string: "1108"),
CBUUID(string: "110A"),
CBUUID(string: "110B"),
CBUUID(string: "110C"),
CBUUID(string: "110D"),
CBUUID(string: "110E"),
CBUUID(string: "110F"),
CBUUID(string: "111F"),
CBUUID(string: "1203"),
CBUUID(string: "1204"),
CBUUID(string: "111E"),
CBUUID(string: "0017"),
CBUUID(string: "0019")]];
print("REGISTERING FOR BR/EDR CONNECTION EVENTS");
self.centralManager!.registerForConnectionEvents(options: matchingOptions);
} else {
// Fallback on earlier versions
};
}
}
Then I implement the callback:
func centralManager(_ central: CBCentralManager, connectionEventDidOccur event: CBConnectionEvent, for peripheral: CBPeripheral) {
print("BR/EDR CONNECTED!!!!");
}
As suggested in the WWDC video I'm going to the phone settings and I can successfully pair my BR/EDR Bluetooth device (a Bluetooth audio box), however the callback is not fired.
I don't known exactly the UUID used by my Bluetooth classic device so I have put in the list all the audio-related UUIDs which I found here.
Are the UUID in the correct form? I also tried by adding them using the long notation (e.g, 0000 1108-0000-1000-8000-00805F9B34FB) but nothing happens, the callback still not fire when device is connected in the Bluetooth settings.
How can I get the UUID advertised by my device?
Thank you in advance
来源:https://stackoverflow.com/questions/58592698/registering-bluetooth-br-edr-classic-connection-in-ios13