简体   繁体   English

iOS:ibeacon 唤醒后恢复 BLE 连接

[英]iOS: resume BLE connection after ibeacon waking up

After the App is killed by the user, if there is a way to resume the previous BLE connection after ibeacon waking up? App被用户杀死后,ibeacon唤醒后是否有办法恢复之前的BLE连接?

In my iPhone application, I could manage to wake up the app using iBeacon after the App is killed by the user.在我的 iPhone 应用程序中,我可以在应用程序被用户杀死后设法使用 iBeacon 唤醒应用程序。 I could trigger local notifications during the wake-up period, but when it comes to BLE related tasks not there is no response at all.我可以在唤醒期间触发本地通知,但是当涉及到 BLE 相关任务时,根本没有任何响应。 No scan callback no connect callback.没有扫描回调没有连接回调。

Edit:编辑:

  1. The BLE background is enabled. BLE 后台已启用。
  2. It scans for a peripheral with the identifier that is previously bonded with iPhone.它会扫描具有先前与 iPhone 绑定的标识符的外围设备。 The identifier is store in Userdefaults.标识符存储在 Userdefaults 中。
  3. For pending connection, when the App is killed, it will call the disconnect callback.对于挂起的连接,当应用程序被杀死时,它会调用断开连接回调。 No pending connection I guess.我猜没有挂起的连接。
  4. I haven't config the BLE state restoration yet.我还没有配置 BLE state 恢复。

Thanks Paulw11 and Prakash Shaiva感谢 Paulw11 和 Prakash Shaiva

After exploring more documents online, here is the answer:在网上查阅了更多文档后,答案如下:

In my case, I want to wake up the App after being killed by users.就我而言,我想在被用户杀死后唤醒应用程序。 And build a connection with a previously bonded BLE device.并与之前绑定的 BLE 设备建立连接。

First thing I learn我学到的第一件事
When iOS App is waken up by ibeacon, it will not call willRestoreState callback. iOS App被ibeacon唤醒时,不会调用willRestoreState回调。 In other word, App cannot restore connection from state restoration support.换句话说,App 无法从 state 恢复支持恢复连接。 But we could attempt to build new connection instead.\但我们可以尝试建立新的连接。\

willRestoreState callback calls when your App is killed by iOS system.当您的应用程序被 iOS 系统杀死时,将调用willRestoreState回调。

Conditions for Bluetooth State Restoration to relaunch your app蓝牙 State 恢复以重新启动您的应用程序的条件
See answer from Apple看苹果的回答

Second thing I learn我学到的第二件事
In order to build new connection during the wake up period, an array of service UUIDs that you're instersted in need to be added to func scanForPeripherals(withServices serviceUUIDs: [CBUUID]?, options: [String: Any]? = nil) , otherwise the random scan will be stopped by iOS itself.为了在唤醒期间建立新的连接,您需要将一组服务 UUID 添加到func scanForPeripherals(withServices serviceUUIDs: [CBUUID]?, options: [String: Any]? = nil) ,否则随机扫描将被 iOS 本身停止。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM