CoreBluetooth didDiscoverPeripheral not called in Swift

I am 99% sure that I correctly followed the instructions for setting up CoreBluetooth . No matter what I do, when I run this application on my iPad mini, Bluetooth talks about it. He says that he scans devices, but he absolutely does not find any devices. If I go to the Bluetooth menu on the device, I will see other detected devices. I initialize the CBCentralManager . I am setting up centralManagerDidUpdateState . When he is sure that Bluetooth is ready, he calls centralManager.scanForPeripheralsWithServices . All of this happens correctly. But the centralManager(central: CBCentralManager!, didDiscoverPeripheral peripheral: CBPeripheral!, advertisementData: [NSObject : AnyObject]!, RSSI: NSNumber!) delegate centralManager(central: CBCentralManager!, didDiscoverPeripheral peripheral: CBPeripheral!, advertisementData: [NSObject : AnyObject]!, RSSI: NSNumber!) never called. My code is very simple. Maybe something is missing me, but I was able to confirm that my Macbook is a BTLE device, and my ipad mini is a BTLE device. Here is my code.

 import UIKit import CoreBluetooth class ViewController: UIViewController, CBCentralManagerDelegate { var centralManager:CBCentralManager! var blueToothReady = false override func viewDidLoad() { super.viewDidLoad() startUpCentralManager() } func startUpCentralManager() { println("Initializing central manager") centralManager = CBCentralManager(delegate: self, queue: nil) } func discoverDevices() { println("discovering devices") centralManager.scanForPeripheralsWithServices(nil, options: nil) } func centralManager(central: CBCentralManager!, didDiscoverPeripheral peripheral: CBPeripheral!, advertisementData: [NSObject : AnyObject]!, RSSI: NSNumber!) { println("Discovered \(peripheral.name)") } func centralManagerDidUpdateState(central: CBCentralManager!) { println("checking state") switch (central.state) { case .PoweredOff: println("CoreBluetooth BLE hardware is powered off") case .PoweredOn: println("CoreBluetooth BLE hardware is powered on and ready") blueToothReady = true; case .Resetting: println("CoreBluetooth BLE hardware is resetting") case .Unauthorized: println("CoreBluetooth BLE state is unauthorized") case .Unknown: println("CoreBluetooth BLE state is unknown"); case .Unsupported: println("CoreBluetooth BLE hardware is unsupported on this platform"); } if blueToothReady { discoverDevices() } } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } } 
+6
source share
1 answer

I had to get my macbook ad. Once I did this using https://github.com/mttrb/BeaconOSX , it worked exactly as I wrote it.

+2
source

Source: https://habr.com/ru/post/973106/


All Articles