There is one requirement in which I need to allow iOS App to communicate with the BLE Hardware when App is Killed by users or OS ( May or May not be forcefully).
This Hardware works as an iBeacon and BLE Peripheral simultaneously!
What we have done is:
- App Launch First Time --> Then Ask for AlwaysUsage Permission
- Start Scanning for iBeacon Region with UUID(uuidString: "{Provided UUID}") only (Minor value will be different)
- When
func locationManager(_ manager: CLLocationManager, didRangeBeacons beacons: [CLBeacon], in the region: CLBeaconRegion)
callback is received, we are extracting Major & Minor value from the detected beacon, preparing a Service UUID string based on this value e.g. if Major value is : 00 & Minor value is "11", concacting this will be "0011" and adding this final concated value as a prefix of device service UUID e.g. "0011-12345-12345-123452" to start scanning for BLE Peripheral.
So my BLECentralManager object would start scanning as
self?.bleCentralManager.scanForPeripherals(withServices: "0011-12345-12345-123452", options: [CBCentralManagerScanOptionAllowDuplicatesKey: false])
Once the Peripheral is detected, rest of the BLE Operations are performed on this peripheral (i.e. Making Connection, Sending data to Specific Characteristic, and at last Drop the connection). This works good in foreground mode.
Now, I need to achieve the same mechanism in Background (i.e. App not running state). How can I achieve it?
NOTE:
- Monitoring for iBeacon region is never stopped. So I am able to awake my app even when it is not launched.
- But my query is, how can I start preparing the Major + Minor value string for the detected Beacon in background