0
votes

After the App is killed by the user, if there is a way to resume the previous BLE connection after ibeacon waking up?

In my iPhone application, I could manage to wake up the app using iBeacon after the App is killed by the user. 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. No scan callback no connect callback.

Edit:

  1. The BLE background is enabled.
  2. It scans for a peripheral with the identifier that is previously bonded with iPhone. The identifier is store in 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.
1
Have you implemented BLE background capability? Are you scanning for a specific service? Do you have a pending connection to the device? Have you configured BLE state restoration? Can you edit your question to show relevant code?Paulw11
@Paulw11 Thanks. I've updated my question.Jalxiey
Right, without state restoration support nothing is going to happen when your app is killed. Also, if you want to reconnect to a known peripheral that you have just disconnected from (ie. it went out of range) then the simplest way is just to call connect in didDisconnect.Paulw11

1 Answers

0
votes

Thanks Paulw11 and 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.

First thing I learn
When iOS App is waken up by ibeacon, it will not call willRestoreState callback. In other word, App cannot restore connection from state restoration support. But we could attempt to build new connection instead.\

willRestoreState callback calls when your App is killed by iOS system.

Conditions for Bluetooth State Restoration to relaunch your app
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.