ibeaconclregion

iOS CLRegion monitoring stops working after a day


I have set up an app to monitor for both geofence (CLCircularRegion) and iBeacon (CLBeaconRegion) monitoring for entry / exit events. Everything works fine for about a day in both foreground and background. I get entry / exit events (generate a UNNotificationRequest to show a local notification) just as I would expect. I can run multiple other apps that would presumably force my app out of memory, and I still get entry / exit events that launch the handler which generates the notification. But a day later I stop getting the events, or at least stop getting the notifications. I'm running iOS 13 on an iPhone Xs. Any insights into what might be happening?


Solution

  • I think I resolved the issue. My CLLocationManager delegate was being set in a ViewController. I discovered watching the console on the device that the region (beacon) was being detected and my app was going to be called, but the delegate was nil. So, I moved setting the CLLocationManager delegate to didFinishLaunching in my AppDelegate, and now everything's working. It makes sense that didFinishLaunching gets called by iOS before calling the delegate method.