[英]iOS BLE background reconnection
我遇到了與設備重新連接的問題。 當我離開BLE設備區域時,離開iPhone大約3分鍾並等待背景然后返回,它將不會重新連接。 我試圖在后台掃描外圍設備,但即使我指定了UUID也無法正常工作。 那有什么解決方案嗎?
func centralManager(central: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, error: NSError?) {
dispatch_async(dispatch_get_main_queue(), {
self.centralManager?.connectPeripheral(self.choosenPeripheral!, options: nil)
})
}
當外設斷開連接時,您只需要在didDisconnectPeripheral
委托方法中再次調用connectPeripheral
; 這將創建一個“待定”連接,一旦外圍設備返回范圍,iOS將連接到它並調用您的didConnectPeripheral
委托方法。
您不需要Dispatch
連接操作。 只需使用:
func centralManager(central: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, error: NSError?) {
central.connectPeripheral(peripheral, options: nil)
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.