1

我在我的 iPad Pro (iOS 11.2) 上遇到了这个奇怪的错误,它发现了外围设备,但无法连接。这几天一直在为此苦苦挣扎。

另一方面,我的 iPhone 可以毫无问题地连接和收集数据。你们中的一些人能指出我这里出了什么问题吗?非常感谢任何帮助。这是我的代码:

//更新:这发生在所有新设备上,例如。iPad Pro、Pixel XL、新的 macbook pro、iPhone 7 等。也许它与新硬件有关?使用 LightBlue 应用程序进行测试。

func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {

    //Use this snippet if the device name is advertised. Optionals are handled well here.
    if let peripheralName = advertisementData[CBAdvertisementDataLocalNameKey] as? NSString {
        if peripheralName as String == deviceDetails.deviceName{
            print("Here I am \(peripheralName)")
            //bleManager.myCentralManager.stopScan()
            myPeripheral = peripheral
            centralManager.stopScan()
            centralManager.connect(myPeripheral, options: nil)
            myPeripheral.delegate = self

           // bleManager.myPeripheral = peripheral
            //bleManager.myPeripheral.delegate = self //Setting the delegate for the peripheral and now we can implement the methods from this view controller
           // bleManager.myCentralManager.connect(bleManager.myPeripheral!, options: nil) //Connecting to the peripheral
            print("Connected to \(myPeripheral)")

        } else {
            //Device name not found
        }
    }
}

//MARK: Step 3 - Connecting to peripheral
func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) {
    print("Connection success")
    peripheral.discoverServices([deviceDetails.service_UUID])           //Discovering specific service
    timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(updateTimer), userInfo: nil, repeats: true)
}

在 iPad 上运行时,我还会粘贴我的日志数据:

powered ON
Here I am GBStrain
Connected to Optional(<CBPeripheral: 0x1c83, identifier = <identifier>, name = GBStrain, state = connecting>)

提前致谢!

4

0 回答 0