加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ios – 如何触发核心蓝牙状态保存和恢复

发布时间:2020-12-15 01:41:41 所属栏目:百科 来源:网络整理
导读:State Preservation and Restoration Because state preservation and restoration is built in to Core Bluetooth,your app can opt in to this feature to ask the system to preserve the state of your app’s central and peripheral managers and to c

State Preservation and Restoration Because state preservation and
restoration is built in to Core Bluetooth,your app can opt in to this
feature to ask the system to preserve the state of your app’s central
and peripheral managers and to continue performing certain
Bluetooth-related tasks on their behalf,even when your app is no
longer running. When one of these tasks completes,the system
relaunches your app into the background and gives your app the
opportunity to restore its state and to handle the event
appropriately.
In the case of the home security app described above,
the system would monitor the connection request,and re-relaunch the
app to handle the centralManager:didConnectPeripheral: delegate
callback when the user returned home and the connection request
completed.

如何触发此操作并测试代码?

我有一个服务配件.我有一个应用程序扫描服务,我选择了状态保存.但是我不确定如何对它进行逻辑测试,因为我不知道触发它需要什么.这些是我尝试失败的选项:

A - kill the app from Xcode

B - kill the app manually

C - power off the phone

D - something else

在所有这些选项中,我试图转到Xcode – >设备并查看日志,但没有看到任何状态恢复日志.

谢谢

解决方法

NB感谢 user1785784分享Apple的 QA1962 – Conditions Under Which Bluetooth State Restoration Will Relaunch An App,它描述了iOS 11中的新蓝牙行为.这个文档应该被认为是这个问题的答案,尽管我认为它错误地声称iOS 10会重新启动一个强制退出的应用程序. (我没有在iOS 10设备上进行测试,但它会偏离iOS 9.任何人都可以确认吗?).

从任务切换器手动杀死应用程序(B),确保在用户再次明确打开应用程序之前,您的应用程序不会自动启动.

C也不起作用,我认为只有VOIP应用程序在重启后自动启动,然后才会在设备解锁后启动.

我不知道任何D.

我用A.

首先,要实现蓝牙状态恢复,请确保您已经完成

> added bluetooth-central作为您的Info.plist的UIBackgroundModes
>在启动CBCentralManager时设置CBCentralManagerOptionRestoreIdentifierKey
>实现了 – (void)centralManager:willRestoreState:CBCentralManager委托中的回调.

然后你准备好测试状态恢复:

>让应用程序进入某种已知状态(例如蓝牙开启,某些设备连接/连接)
>在Xcode中杀死应用程序
>观看日志或set a launch breakpoint
>改变蓝牙状态,例如通过

>切换航空公司模式
>将蓝牙设备超出范围(为了避免走路,我将我放入导体/法拉第笼/咖啡壶)
>将设备带回范围
>与设备交互,例如按一下按钮/有一个脉冲

>观察您的州恢复代码

注意:application:didFinishLaunchingWithOptions:将首先被调用,你必须立即启动你的CBCentralManager,如上所述.然后将调用centralManager:willRestoreState:.

A coffee pot that is also a Faraday Cage

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读