[英]Can iOS re-connect to Bluetooth LE peripheral by specifying )CBPeripheral *)peripheral instead of doing retrievePeripherals?
当我得到委托didConnectPeripheral:(CBPeripheral *)peripheral
时,我可以只将外围设备存储在一个数组中,然后用它稍后重新连接,而不是使用retrievePeripherals及其后续的didRetrievePeripherals
吗? 如果可行且没有风险,似乎会更容易。
(CBPeripheral *)peripheral
可以再使用(CBPeripheral *)peripheral
? 与该外围设备断开连接后,它仍然有效吗?
工作流程:
scanForPeripheralsWithServices()
-扫描外围设备 didDiscoverPeripheral:(CBPeripheral *)peripheral
检测到connectPeripheral:peripheral
didConnectPeripheral:(CBPeripheral *)peripheral
stopScan并存储(CBPeripheral *)peripheral
供以后使用。 cancelPeripheralConnection
didDisconnectPeripheral
稍后,重新连接...
connectPeripheral:peripheral
来自具有外围设备的阵列 didConnectPeripheral:(CBPeripheral *)peripheral
... 是的,它会起作用(但这是很糟糕的做法)。 retrievePeripherals:
方法是专门创建的,因此您可以在应用程序的后续启动之间重新连接到外围设备。 您可以使用您的方法,但是一旦应用程序关闭,您将永远无法再次连接到外围设备(无需将其置于广告模式并基本上从头开始)。 您可以在CBPeripheral
启动之间存储uuid,但不能存储CBPeripheral
对象。 因此,这里有很大的缺点。
综上所述:它可以工作,但并不能真正为您带来任何好处。 它不比调用retrievePeripherals:
然后连接它们快。 建议的方法仅限制CoreBluetooth
连接能力。 但是仍然有一个有趣的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.