I have a use case where there are 2 devices. One is a Apple Mobile phone running a IOS application and other is a BLE enabled IOT device.
How can I address this problem?
While iBeacon is very fast at detecting in the background and works best, it is not absolutely necessary. You can detect a BLE service on iOS in the background and connect to it when it is discovered.
To do this you must:
<key>UIBackgroundModes</key>
<array>
<string>bluetooth-central</string>
</array>
didFinishLaunching
you must trigger a BLE scan startcentralManager?.scanForPeripherals(withServices: [myServiceUUID], options: nil)
If you do the above, after your app is terminated, iOS will auto-launch your app and you will get a callback to didDiscoverPeripheral
when a new peripheral is discovered.
While this really does work, it is very difficult to test correctly because of the way iOS keeps track of duplicates. If a device has been detected already, and you kill your app you will not get a callback about its discovery -- iOS keeps track that it was already detected. It will only give you a launch and callback for a new device.
Here is how I would test it:
The phone reboot step above is critical to clear out the cache of what devices the iPhone has already seen and are therefore ineligible for a callback.
Finally, you can accelerate this process with a BLE device that also advertises iBeacon as background detections are much faster and less temperamental. But as you note, you cannot use iBeacon to connect to a peripheral using CoreBluetooth. So you must advertise BOTH from your BLE device. This is a common approach I use all the time. Use iBeacon to accelerate the wake-up of your app and CoreBluetooth service advertisement detections to establish a connection.