I have one Smart Door unlock hardware device which acts as iBeacon and CoreBluetooth Peripheral simultaneously!
What my requirement is when my app is launched first-time, the app will start monitoring the iBeacon Region and when the user's distance is less than 10 meters, the application should start scanning the BLE Peripheral using specific CBService.
When a user comes within a 0.5-meter distance, the app should automatically connect with the scanned CBPeripheral device & process door open operation.
You can imagine it as the app will get activated when you're nearer (Approx 10 meters away) from the entrance of the building & start scanning the nearest Bluetooth H/w. When you're reaching to the entrance, the door will get opened automatically by performing some Bluetooth operation.
Can anyone help me with how can I achieve similar behavior using CoreBluetooth tech?
This app should work in background mode as well.
What I have done till now is, started iBeacon region monitoring and getting callback in
func locationManager(_ manager: CLLocationManager, didRangeBeacons beacons: [CLBeacon], in region: CLBeaconRegion) {
// I am using beacon's accuracy as distance calculation.
// When accuracy is < 10 meter, I am starting Peripheral scanning using: centralManager.scanForPeripherals(withServices: [{My Custom Service UUID}], options: [CBCentralManagerScanOptionAllowDuplicatesKey: false])
}
My Bluetooth manager gets a callback about
func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {
}
Now how can I map with my iBeacon and Discovered Peripheral & make an automatic connection with Peripheral when the distance is < 0.5 meters.
In short, my mobile should work as an RFID card for Authentication & Attendance management
I want to achieve similar behavior as displayed in the following video: https://www.youtube.com/watch?v=Y6XlVE7UKp0