在Core Bluetooth中断开连接后如何重新连接到设备 [英] How can I reconnect to device after disconnecting in Core Bluetooth

查看:84
本文介绍了在Core Bluetooth中断开连接后如何重新连接到设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Core Bluetooth中,连接到设备后,我关闭了设备,并断开了设备的连接.但是,当我再次打开设备时,没有再次调用didDiscoverPeripheral.如何重新连接到设备?

In Core Bluetooth, after connecting to a device, I turn off the device and the device is disconnected. But when I turn on the device again, there is no didDiscoverPeripheral called again. How can I reconnect to the device again?

推荐答案

使用cancelPeripheralConnection断开设备的连接时,将调用didDisconnectPeripheral委托方法.但是,从iOS 6.0起,设备将保持连接状态约40至50秒(或更长时间),因此在该时间内不会调用didDiscoverPeripheral.如果您想再次发现"它,只需调用retrieveConnectedPeripherals方法,您将在didRetrieveConnectedPeripherals中获得引用.

When you disconnect a device with cancelPeripheralConnection the didDisconnectPeripheral delegate method will be invoked. However from iOS 6.0 the device remains connected for about 40-50 seconds (or more), so no didDiscoverPeripheral will be invoked in that timeframe. If you want to "discover" it again just call the retrieveConnectedPeripherals method and you will get the reference in didRetrieveConnectedPeripherals.

但是,最好的解决方案是保存设备的UUID,并使用它与retrievePeripherals方法重新连接.这将调用didRetrievePeripherals,并且您可以与connectPeripheral重新连接.这是重新连接设备的最快方法,在这种情况下无需扫描.

However, the best solution is to save the device's UUID and use that to reconnect with the retrievePeripherals method. This will invoke didRetrievePeripherals and you can reconnect with connectPeripheral. This is the fastest way to reconnect to a device, no scanning is required in this case.

这篇关于在Core Bluetooth中断开连接后如何重新连接到设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆