Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/107.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios CBR外围设备连接问题_Ios_Swift_Bluetooth_Bluetooth Lowenergy - Fatal编程技术网

Ios CBR外围设备连接问题

Ios CBR外围设备连接问题,ios,swift,bluetooth,bluetooth-lowenergy,Ios,Swift,Bluetooth,Bluetooth Lowenergy,CBCentralManager在连接到设备时卡住 开始扫描后,它找到设备并到达centralManager:didDiscover:方法,然后尝试连接到该设备,但该设备保持连接状态一段时间,然后断开连接 通过在设备上重新启动蓝牙很容易修复,但这不是一个解决方案。有人知道为什么会这样吗 代码: 此外,我还从console获取了该日志: 2017-05-21 21:09:32.049137 MyApp[5871:2645747] [Fabric] Unable to locate applicat

CBCentralManager在连接到设备时卡住

开始扫描后,它找到设备并到达centralManager:didDiscover:方法,然后尝试连接到该设备,但该设备保持连接状态一段时间,然后断开连接

通过在设备上重新启动蓝牙很容易修复,但这不是一个解决方案。有人知道为什么会这样吗

代码:

此外,我还从console获取了该日志:

2017-05-21 21:09:32.049137 MyApp[5871:2645747] [Fabric] Unable to locate application icon
2017-05-21 21:09:32.051153 MyApp[5871:2645747] [Crashlytics] Version 3.8.4 (121)
Scanning started
self.peripheralManager powered on.
Connecting to peripheral <CBPeripheral: 0x1700f9100, identifier = B5E6ACBF-307C-4C13-BB6A-09F4A92ABEC3, name = (null), state = connecting>
我在控制台中看到:

Connecting to peripheral <CBPeripheral: 0x1700f9100, identifier = B5E6ACBF-307C-4C13-BB6A-09F4A92ABEC3, name = (null), state = connecting>
连接到外围设备

所以10秒后外设仍然存在。因此,解除分配和强引用不成问题。

您可以
self.discoveredPeripheral=。外围设备
仅在一种情况下。因此,它可能与一个强大的/解除分配的问题有关。当您在
retievedPeripherals
中检索到它时,是否在那里保留引用?此外,在这种情况下,您不会设置委托,因此不会为其调用委托方法。实际上,它应该可以在不连接retievedPeripherals的情况下工作。在下面的几行中,我正在执行self.discoveredPeripheral=peripheral self.discoveredPeripheral?.delegate=self-central.connect(peripheral,options:nil)从该点开始连接,但它仍处于连接状态。重启蓝牙后,它也能正常工作
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 10.0) {
   print("Connecting to peripheral \(peripheral)")
}
Connecting to peripheral <CBPeripheral: 0x1700f9100, identifier = B5E6ACBF-307C-4C13-BB6A-09F4A92ABEC3, name = (null), state = connecting>