iOS 15 does not awake app while entering BLE beacon region

Viewed 1672

My iOS app has BLE beacons detection in it. Which means If user has bluetooth and location on and if user enters the range of a beacon, system automatically awakes the app If it was not running (killed state).

This was working fine on iOS 14 and below. Yesterday I updated my device to iOS 15 and app no longer gets awoken while entering a ble beacon region even If I have enabled "Always" location permission in the settings.

Any thoughts ?

3 Answers

My tests show that iOS 15 successfully launching an app from a stopped state into the background on beacon region entry.

Test steps:

  1. Install this app on my phone with iOS 14.8: https://github.com/davidgyoung/CoreLocationRegionLaunchDemo

  2. Run the app, grant notification and location always permissions.

  3. Go to settings and verify location permission is always

  4. Turn on a beacon, verify an entry notification arrives. Then turn off the beacon, verify the exit notification arrives.

  5. Reboot the phone. Wait 5 minutes. Turn on the beacon, then verify the entry notification arrives. Turn off the beacon and verify the exit notification arrives.

  6. Upgrade to iOS 15.

  7. Wait 5 mintues.

  8. Turn on a beacon. Verify an entry notification arrives.

See screenshots -- sorry they are ugly, but I have to finish the giant download of XCode 13 before I can send screenshots directly to my computer.

enter image description here

enter image description here

After trial/error, testing, and conversations with Apple, I can confirm it's not a bug with region monitoring, it's a bug with Apple's new prewarming feature in iOS 15.

In a nutshell, iOS 15 will half-launch apps silently in the background that iOS believes the person will use. In our testing this happens about every half hour. It makes app launching feel faster because a bunch of the app is already loaded and ready to go.

If Apple prewarms your app, and the user doesn't fully launch it, and then a region monitor needs to notify your app, it won't happen. That's sometimes region monitoring alerts your app and sometimes it doesn't. If your app is "cold", it will work. If your app is in memory, it will work. If your app is in this prewarm state, you are dead in the water.

Rebooting the whole phone works, because you're evicting any app in a prewarmed state.

I have it from Apple that this is really multiple bugs, some fixed and some not yet. The notes in the iOS 15.2 betas also specifically mention this likely affects HealthKit too.

The solution that works around the bug is to detect in main.m when Apple is prewarming your app and exit. This doesn't permit your app to launch when Apple prewarms and forces your app to fully boot when the time comes.

Here's the code for inside the main() method inside main.m. Note that it's prudent to add an iOS version detection so when Apple does fix this it can eventually be phased out and removed.

double systemVersion = [[UIDevice currentDevice] systemVersion].doubleValue;
if (systemVersion >= 15.0) {
    NSDictionary* environment = [[NSProcessInfo processInfo] environment];
    BOOL prewarmed = false;
    for (NSString *key in environment.allKeys) {
        if ([key.lowercaseString containsString:@"prewarm"]) {
            prewarmed = true;
            break;
        }
    }

    if (prewarmed) {
        exit(0);
    }
}

It's weird, in my case, reboot seems to solve the problem.

Related