I have asked this question a few times (here and here) with no usable responses so I will ask this in a different way now...
What I need
I need to be able to wake my app up from terminated, send and receive some data from a Bluetooth peripheral I have programmed myself. This is important data for security reasons so I absolutely need the app to wake up. However, the device isn't always on most times it's powered off, so therefore I need this use case to be handled when the peripheral is turned on/off. To do this I need to use iBeacon to wake up the app, send a command to the box, get a response and then go into continuous exchange mode. If the peripheral device is turned off I don't care, just when it's turned back on thats when I need the process of continuous data exchange to restart.
The Problem
I have tried all the suggested background "app wakable" info.plist items... Voip, background audio, iBeacon and bluetooth didConnectPeripheral
/didDisconnect
delegate methods and nothing really works very reliably. For a few days I had the iBeacon didEnterRegion
and didExitRegion
methods firing when I would plug/unplug my device so at least theres something sort of reliable.
The real problem begins if I use iBeacon to wake up the app and connect to bluetooth (because I cant exchange info with the box until I connect/pair at the iOS system level). Because the app hasn't been paired with yet, none of the commands in the background ever make it to the box. When this process is started in the background, no message comes up asking if you would like to pair with this device (it all works fine when app is running and you can pair).
Also, even if I did get a chance to pair then I would now be connected/paired permanently (which I wouldn't want the user to have to press "pair" every time I plug in the device and the app is closed). Unless the user goes into bluetooth settings and "forgets the device" then I can't disconnect them. Therefore I have just lost my ability to use iBeacon to wake up the app once it gets closed, because now iBeacon will never fire so long as the app is connected via Bluetooth.
My Question(s)
How are other apps doing this so easily and what's the proper flow for permanently waking your app from background/terminated? I am struggling to figure out the flow here.
Am I really expected to only use iBeacon in use cases where no connectivity or pairing is also required? Am I supposed to disconnect the user somehow from the peripheral?
Summation
So in summary, using iBeacon for waking up the app, doesn't work if you need to connect/pair to a peripheral because then those methods will never fire again until no longer paired/connected. If I were to find some magic way to disconnect a person when the app dies and revert back to iBeacon, it wouldn't work because I can't seem to pair from the background so the commands don't make it to the peripheral. Lastly, if I use a purely connected Bluetooth approach, the didConnect
and didDisconnect
methods never fire when I plug/unplug the device.