iOS 15 does not awake app while entering BLE beacon region
Asked Answered
N

3

3

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 ?

Nicker answered 21/9, 2021 at 7:29 Comment(7)
A few things to try for completeness of diagnosis: (1) If you launch the app manually, does it detect from the foreground? (2) if you then exit the region and out the app to the background, can it then detect again from the background? (3) if the first two tests work, then if you exit the region, reboot your phone (waiting 5 mins after reboot without launching you app) then go in range of the beacon, does it detect?Bandwagon
@Bandwagon I can confirm that first two tests worked fine. Third test did not work. App was not detected/launched by beacon when I entered the region.Nicker
@Bandwagon any updates on it ?Nicker
I added local notifications in different functions like EnteredRegion, LeftRegion, DidDeterminedState and DidRangeBeacons. If I close app totally, go out of the range and come back into the region, devices running on iOS 14 or lower wake up and I get notifications from EnteredRegion, DidDeterminedState & DidRangeBeacons. But I don't get any notification on device running on iOS 15. Provided that I have enabled "always" location permission on all the devices.Nicker
In our extensive bug report about this issue (beacon monitoring specifically) the status has been updated to 'Potential fix identified - For a future OS update'.Numerate
@Numerate can you please share a link to your bug report?Bandwagon
@Bandwagon Sure: feedbackassistant.apple.com/feedback/9792014Numerate
B
2

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

Bandwagon answered 23/9, 2021 at 15:57 Comment(3)
I have seen a weird behaviour. After reboot test, app got launched in the background. DidRange started getting called. If I lock screen, i don't receive didRange notifications. As soon as I turn on the display, i start receiving didRange notifications again.Nicker
I tried your code which works fine but there is one issue which I have explained here #69315874Nicker
Good to hear! If this answers this question, please mark this answer as accepted so other folks will be able to find the solution.Bandwagon
D
2

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);
    }
}
Documentation answered 11/1, 2022 at 21:56 Comment(2)
Have you confirmed this works to defeat prewarming?Bandwagon
Confirmed. Also, Apple fixed this behavior in iOS 15.4, so you can limit this hack to 15.x prior to that.Documentation
M
0

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

Meadowlark answered 8/10, 2021 at 14:31 Comment(3)
But I did not ever think about rebooting(until I saw davidgyoung's answer), not to mention the customers. It would be a disaster for the apps online, which relys on this functionality.Meadowlark
Users would not want to reboot their phones every time they run into this problem. Is there any other workaround?Nicker
@JasonRoy In my case, only one reboot required, then it worked fine(but it also hard to inform every user to reboot). But I don't know whether the problem occurs again or not.Meadowlark

© 2022 - 2024 — McMap. All rights reserved.