Situation:
We have an app that only uses location UIBackgroundModes key to restart our app on significant change events as we need it to connect with a BLE device (mounted in the car) when someone starts driving. We cannot use geofence as the car might be used by multiple people so position changes and we don't want to store locations and sent them to multiple users via our servers. So currently we use significant change and just ignore all other location data.
During app review we got the following feedback:
If the app does not require persistent real-time location updates, please remove the "location" setting from the UIBackgroundModes key. You may wish to use the significant-change location service or the region monitoring location service if persistent real-time location updates are not required for the app features.
Question: How to use the significant-change location service without the "location" setting from the UIBackgroundModes key or is there any other way to start the app / connect with the BLE device when it is fully terminated/swiped away? Because the docs state that AuthorizationStatusAuthorizedAlways is required and without the UIBackgroundModes key location that wouldn't be triggered when app is in the background/swiped away.
I am not sure why CoreBluetooth alone is not starting your app.
First, have you opted in to Bluetooth State Restoration? Because that is the only way your app will be restarted if it has been terminated.
If you have not, there is more information in Performing Long-Term Actions in the Background on how to implement this.
Once you have that implemented, then the system will relaunch your app after termination, when there is a need to respond to the Bluetooth device, for example, a connection is established for a pending connectPeripheral call.
One downside to this, if the user force quits the app, or turns off Bluetooth, then this won't work. The only way your app will be restored after a user force quit is if you migrate your app/device to be discovered by AccessorySetupKit first.
TN3115: Bluetooth State Restoration App Relaunch Rules explains the conditions where the app will be restored or not.
Significant Location Change API does not have this limitation and will relaunch the app despite a force quit, which is why, I presume, you opted in to using location services.
While technically this is an off-label use, if it is working for you...
And, when I said scanning, it did not mean you have to use scanForPeripherals. connectPeripheral is fine as long as you have valid peripheral IDs.
Behind the scenes, the connectPeripheral call splits into a scan and then connect request. But while the app is in the background, calling connectPeripheral is going to be faster to connect than making the scan/connect calls yourself. So, you are doing the correct thing there.
Argun Tekant / WWDR Engineering / Core Technologies