7

We are developing an app that should respond to an iBeacon and circular regions in the background.

Sometimes it works perfectly, but sometimes the beacon and circular region enter/exit stop suddenly.

In the app, we are using(in background mode)

  • Significant location updates
  • Beacon region monitoring
  • Circular region monitoring
  • Continuous location updates for some actions

Any idea? It seems to me that in the background regions detection sometimes stopped working suddenly

Could it be the problem?

  • Seeing the same problems in iOS 15 since upgrading. Sometimes Apple launches app in the background, sometimes it does not. – Brandon Medenwald Oct 06 '21 at 18:35
  • For anyone watching this issue, I've formatted submitted a support ticket off to Apple. We have been able to reproduce this bug in a small sample app, which makes this increasingly look like an iOS 15 bug on Apple's part. – Brandon Medenwald Oct 07 '21 at 17:47
  • @Ankur Kalkani , I am facing the same problem with my app. Have you heard from Apple on this? Or have you found any workaround to solve this problem ? – Ali Raza Oct 10 '21 at 14:58
  • From Apple: "I can't provide a great deal of specific detail, but I do want to make it clear that this issue is being actively worked on and investigated. There have actually been a series of issues and fixes some of which have shipped, and that 'mixed' state has made the issue somewhat 'confused'." – Brandon Medenwald Dec 08 '21 at 15:39
  • 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'. – Thermometer Dec 17 '21 at 09:23

2 Answers2

7

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.

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);
    }
}
  • Hi Brandon, thanks for yout example and research. But according to: https://developer.apple.com/library/archive/qa/qa1561/_index.html#//apple_ref/doc/uid/DTS40007952 You should never call exit(0); in the code. Got any tips, what to do instead? I have an issue with an app not always opening, when entering an iBeacon area, due to prewarming. – Søren Reinke May 31 '22 at 07:46
  • 2
    Sure, you shouldn't call exit, but you shouldn't also have to do this silly workaround nonsense. This was the only solution that worked for us. FWIW: Apple did fix this bug starting in iOS 15.4, so you only need to do this for iOS 15.0 thru iOS 15.3.x – Brandon Medenwald Sep 06 '22 at 16:27
0

There have been two recent reports of region monitoring failing on iOS 15:

IOS 15 Ibeacon monitoring

iOS 15 does not awake app while entering BLE beacon region

The above are for CLBeaconRegion monitoring, but whatever problem exists may apply to CLCircularRegions as well.

I tried doing a controlled test in my answer to the second question above to reproduce this across an iOS 15 upgrade. I could not reproduce the problem. So this does not appear to be a universal issue.

You might try rebooting or reinstalling your app to see if these changes make a difference. Any updates based on the results of these tests would be welcome.

davidgyoung
  • 63,876
  • 14
  • 121
  • 204