How to know when to retrieve connected ble device while app is in background and its connected first in ios system?

若如初见. 提交于 2019-12-20 07:23:03

问题


Our BLE device is using ANCS and being connected as peripheral in the ios app. My problem happens in case when watch is being connected in settings screen first then it doesnt show up in scanned device thats why its not connecting while app is in background because its getting connected outside of the app, reason being iphone is bonded with ble device. Though I can retrieve it using retrievePeripheral function. But it has to be manually fired , I am looking for some kind of observer or delegate function which is called when a BLE device is called through system so I can retrieve peripheral. How to connect while app is in background and ble device is connected in Settings first? One solution I was thinking is run a timer which will call this retrievePeripheral function after a fixed interval, but that will be battery consuming. If anybody have better idea please enlighten me.

I have tried almost everything , I know scan function works in background with service ids but I am talking about the scenario where device is undiscoverable as it got connected in settings screen first.


回答1:


Seems like I don't need to scan for device once its discovered, connected and successfully paired. In didDisconnect function I am retrieveing the ble device and sending a connect request See this, this function doesn't time out. Whenever BLE device will come into the range it will be connected.



来源:https://stackoverflow.com/questions/53321747/how-to-know-when-to-retrieve-connected-ble-device-while-app-is-in-background-and

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!