简体   繁体   中英

Eddystone beacon background tracking for ios

I would like to know if something like this is actually possible with Eddystone beacon tracking on iOS.

I am currently working on app which should be scanning Eddystone beacons. The basic idea of the app is: - User opens the app; - User registers for the meeting at specific time (in the future); - Start BT scanning 5 minutes before start of the meeting; - When beacons found do a network request and show notification to the user.

If the app is in the foreground the there is no problem. Just call

func startScan() {
    if centralManager.state == .poweredOn {
        let services = [CBUUID(string: "FEAA")]
        let options = [CBCentralManagerScanOptionAllowDuplicatesKey: true]
        centralManager.scanForPeripherals(withServices: services, options: options)
    }
}

An it will start scanning. Then when the beacon is found and I get the correct data from the server I will stop the scan.

So the question would be if it is somehow possible to schedule the start of the scan even when the app is in background? Of course if it's killed then we can't do anything with that.

One idea was to create some "silent local notification" but then after reading through Apple docs it seems like

func userNotificationCenter(_ center: UNUserNotificationCenter,
                            willPresent notification: UNNotification,
                            withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
}

is called only when app is in foreground?

Any help or suggestion would be appreciated.

You cannot schedule a Bluetooth scan to start at a specific time if the app is not running in the foreground. And there is no reliable way to kickstart your app with notifications (remote or local) at a very specific time. Silent remote notifications are possible, but they can take many minutes to be delivered.

What you can do is set up scanning for the Eddystone service UUID so up get a single discovery callback by CoreBluetooth when your app is in the background and sees a beacon for the first time. The main catch is that this is also not super fast. Detection might come within a few seconds, bit more likely in a minute or two after the beacon is in the vicinity.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM