Ranging does not recognise beacon again once back in foreground

Hi everyone,

I cannot find a solution to the following issue I am facing. In this small test app, which I set up based on the tutorial for ranging on iOS, my code looks like this:

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, ESTBeaconManagerDelegate {

    var window: UIWindow?

    let beaconManager = ESTBeaconManager()
    let beaconRegion = CLBeaconRegion(
        proximityUUID: UUID(uuidString: "4936C7D0-DC7A-4B3D-8402-64E4501EEC64")!,
        identifier: "1234567890")

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.

        self.beaconManager.delegate = self
        self.beaconManager.requestAlwaysAuthorization()
        self.beaconManager.startMonitoring(for: self.beaconRegion)
        self.beaconManager.startRangingBeacons(in: self.beaconRegion)

        UIApplication.shared.registerUserNotificationSettings(
            UIUserNotificationSettings(types: .alert, categories: nil))

        return true
    }

    func beaconManager(_ manager: Any, didRangeBeacons beacons: [CLBeacon],
                       in region: CLBeaconRegion) {
        NSLog("Region Ranging: active ...")
        if (beacons.count > 0) {
            print(beacons)
        }
    }
}

Once I run the app on my iPhone and check the log, it looks like this:

2017-09-05 19:23:51.919030+0100 Estimote Test[1691:498775] Region Ranging: active ...
2017-09-05 19:23:52.930651+0100 Estimote Test[1691:498775] Region Ranging: active ...
[CLBeacon (uuid:4936C7D0-DC7A-4B3D-8402-64E4501EEC64, major:1, minor:1, proximity:1 +/- 0.07m, rssi:-55)]
2017-09-05 19:23:53.926099+0100 Estimote Test[1691:498775] Region Ranging: active ...
2017-09-05 19:23:54.917538+0100 Estimote Test[1691:498775] Region Ranging: active ...
[CLBeacon (uuid:4936C7D0-DC7A-4B3D-8402-64E4501EEC64, major:1, minor:1, proximity:1 +/- 0.08m, rssi:-56)]
2017-09-05 19:23:55.926351+0100 Estimote Test[1691:498775] Region Ranging: active ...
2017-09-05 19:23:56.918447+0100 Estimote Test[1691:498775] Region Ranging: active ...
[CLBeacon (uuid:4936C7D0-DC7A-4B3D-8402-64E4501EEC64, major:1, minor:1, proximity:1 +/- 0.08m, rssi:-56)]
2017-09-05 19:23:57.919728+0100 Estimote Test[1691:498775] Region Ranging: active ...
[CLBeacon (uuid:4936C7D0-DC7A-4B3D-8402-64E4501EEC64, major:1, minor:1, proximity:1 +/- 0.09m, rssi:-57)]
2017-09-05 19:23:58.917537+0100 Estimote Test[1691:498775] Region Ranging: active ...
2017-09-05 19:23:59.917476+0100 Estimote Test[1691:498775] Region Ranging: active ...
2017-09-05 19:24:00.915645+0100 Estimote Test[1691:498775] Region Ranging: active ...
2017-09-05 19:24:01.918962+0100 Estimote Test[1691:498775] Region Ranging: active ...
[CLBeacon (uuid:4936C7D0-DC7A-4B3D-8402-64E4501EEC64, major:1, minor:1, proximity:1 +/- 0.08m, rssi:-56)]
2017-09-05 19:24:02.923122+0100 Estimote Test[1691:498775] Region Ranging: active ...

Once I put the app to background, and come back after a few minutes, without touching the beacon, the log looks like this:

2017-09-05 19:28:17.874827+0100 Estimote Test[1691:498775] Region Ranging: active ...
2017-09-05 19:28:18.892604+0100 Estimote Test[1691:498775] Region Ranging: active ...
2017-09-05 19:28:55.902272+0100 Estimote Test[1691:498775] Region Ranging: active ...
2017-09-05 19:28:56.901704+0100 Estimote Test[1691:498775] Region Ranging: active ...
2017-09-05 19:28:57.896723+0100 Estimote Test[1691:498775] Region Ranging: active ...
2017-09-05 19:28:58.901165+0100 Estimote Test[1691:498775] Region Ranging: active ...
2017-09-05 19:28:59.907081+0100 Estimote Test[1691:498775] Region Ranging: active ...
2017-09-05 19:29:00.899307+0100 Estimote Test[1691:498775] Region Ranging: active ...
2017-09-05 19:29:01.901167+0100 Estimote Test[1691:498775] Region Ranging: active ...

Am I getting sth wrong about the concept of ranging? Should “didRangeBeacons” with normal behaviour not pick up that same beacon again? I tried with different beacons, always the same behaviour.

Thank you for a hint in the right direction!

I wonder, do you have Smart Power Mode enabled on your beacon? Can you try disabling it and see if the problem persists? Smart Power Mode reduces beacon’s adv frequency when the beacon is not in use, so I wonder if that’s somehow connected here.

What is your beacon’s advertising interval? It’s slightly worrying that even the first time when you try this, there are ranging events where the beacon is not in the ranging results.

Actually, I have tested it with different beacons (also not Estimote ones), and also set up my Mac to act as a beacon (where I definitely did not activate something like a smart power mode). Always with the same result. So it cannot be related to the beacon itself or the advertising interval I guess?

I also have to point out, that the ranging events in the first logs which I provided might be an unlucky example, since in other tests which I performed, it would recognise the beacon signal in every one of the ranging events - at first. But, after moving the app to the background and then foreground again, I am left with the same problem: it does not pick up the beacon signal anymore.

I am running the tests on an iPhone 5s with iOS 10.3.2. Would it be worth switching to other phones to check the results?

Or have you ever heard of a similar issue which would be related to the software / my code?