相关疑难解决方法(0)

如何在ios swift中连接低功耗蓝牙?

我想连接 ble 外设。但我的代码没有调用 didConect 函数

这是我的代码:

func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {
 let device = (advertisementData as NSDictionary)
            .object(forKey: CBAdvertisementDataLocalNameKey)
            as? NSString

        if device?.contains(BEAN_NAME) == true {

            print("Did discover peripheral", peripheral)

            self.bluetoothManager.stopScan()
            self._peripheral = peripheral
            self._peripheral.delegate = self
            central.connect(peripheral, options: nil)
        }
}


func centralManager( central: CBCentralManager, didConnect peripheral: CBPeripheral) { //cant call this
        print("connected to \(BEAN_NAME)")
        peripheral.discoverServices(nil)
    }
Run Code Online (Sandbox Code Playgroud)

日志:

BLE service is powered on
Did discover peripheral <CBPeripheral: 0x1740eef00, identifier …
Run Code Online (Sandbox Code Playgroud)

ios bluetooth-lowenergy swift beacon

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

beacon ×1

bluetooth-lowenergy ×1

ios ×1

swift ×1