无法连接某些iOS设备的BLE外围设备

3

iOS 14.4.2的7 Plus和iOS 12的6上BLE工作正常,但是在XR(14.4.2)和11上,在centralManager.connect(peripheral, options: nil)之后连接会卡住(无限连接)。

其他智能手机无法检测到外围设备,因此该外围设备处于连接模式。起初我以为问题出在外围设备本身的无线电模块(NRF52),但是调试板也出现了该问题。重新启动智能手机没有帮助。

有趣的是,在装有M1芯片的MacBook上,应用程序运行良好。

代码的一部分:

// Peripheral model

init(withPeripheral peripheral: CBPeripheral, advertisementData advertisementDictionary: [String : Any], andRSSI currentRSSI: NSNumber, using manager: CBCentralManager) {
    centralManager = manager
    basePeripheral = peripheral
    RSSI = currentRSSI
    super.init()
    advertisedName = parseAdvertisementData(advertisementDictionary)
    basePeripheral.delegate = self
}

public func connect() {
    centralManager.delegate = self
    centralManager.connect(basePeripheral, options: nil)
    print("Connecting to \(advertisedName ?? "device")...") 
// logs stops here
}

public func disconnect() {
    centralManager.cancelPeripheralConnection(basePeripheral)
    print("Cancelling connection with \(advertisedName ?? "device")...")
// triggers on VC dismiss
}

func centralManagerDidUpdateState(_ central: CBCentralManager) {
    if central.state != .poweredOn {
        print("Central Manager stated changed to \(central.state)")
    }
}

func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) {
    if peripheral == basePeripheral {
        print("Connected to \(advertisedName ?? "device")")
        delegate?.peripheralDidConnect()
        discoverPrimaryServices()
    }
}

func centralManager(_ central: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, error: Error?) {
    if peripheral == basePeripheral {
        print("Disconnected from \(advertisedName ?? "device")")
        delegate?.peripheralDidDisconnect()
    }
}
1个回答

4

"其他智能手机无法检测到外设,因此该外设处于连接模式中。" 你是指其他智能手机不能检测到它吗?

考虑到你列出的可工作和不可工作的手机,我认为你的板子可能在使用蓝牙5.0时遇到了问题(该技术最初在iPhone 8上得到支持)。 NRF52支持BT5(它支持5.2),但如果你自己编写固件,可能会破坏其支持。我建议首先确保你正在运行来自Nordic的最原始的代码。


我的意思是,当外围设备在连接到智能手机的阶段冻结时,它会从扫描仪中消失,即它似乎正常工作,没有错误和断开连接,但在某些设备上无法完全连接。我根据nRF Blinky应用程序编写了我的代码,当然进行了相当大的修改,但基础和一般模式保持不变。实际上,我替换了UUID服务和特征,并添加了许多自己的内容。你说问题可能在板子本身的固件中,我会尝试在那里寻找问题,谢谢。 - Tim Yumalin
1
所以我们安装了NRF52(UART)的原始固件,基于此编写了我们的软件并成功连接,显然问题确实在外设设备的一侧。感谢提示! - Tim Yumalin

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接