如何知道当应用程序在后台且其在ios系统中首先连接时何时检索连接的ble设备? [英] How to know when to retrieve connected ble device while app is in background and its connected first in ios system?

查看:107
本文介绍了如何知道当应用程序在后台且其在ios系统中首先连接时何时检索连接的ble设备?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的BLE设备正在使用ANCS并作为ios应用程序中的外围设备进行连接.我的问题发生在万一手表先在设置屏幕中连接,然后它没有出现在扫描设备中的情况下,这就是为什么它在应用程序处于后台时未连接的原因,因为它在应用程序外部进行了连接,原因是iphone与ble设备绑定了. 尽管我可以使用 retrievePeripheral函数进行检索.但是它必须手动触发,我正在寻找某种通过系统调用BLE设备时调用的观察者或委托函数,以便我可以检索外围设备. 当应用程序处于后台并且先在设置"中连接设备时如何连接? 我在想的一个解决方案是运行一个计时器,该计时器将在固定的时间间隔后调用此retrievePeripheral函数,但这会消耗电池.如果有人有更好的主意,请赐教.

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.

我已经尝试了几乎所有方法,我知道扫描功能可在具有服务ID的后台运行,但我所谈论的是设备由于首先在设置屏幕中被连接而无法发现的情况.

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.

推荐答案

好像我不需要在设备被发现,连接并成功配对后就进行扫描. 在didDisconnect函数中,我正在检索ble设备并发送连接请求参见此,此功能不会超时.只要BLE设备进入该范围,它将被连接.

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.

这篇关于如何知道当应用程序在后台且其在ios系统中首先连接时何时检索连接的ble设备?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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