I'm working on an iOS app that monitors for iBeacon regions. When the app is running in the background, I want it to send a local notification whenever it encounters a particular iBeacon region. Everything works fine, except for one thing: locationManager: didEnterRegion evidently doesn't get called until the user displays the lock screen. So even if the device passed through an iBeacon region while the app was in the background, they don't get the notification until they display the lock screen.
I've also tried using startMonitoringForRegion, and that sort of works -- if the app is running in the background, locationManager: didDetermineState: fires when the device enters the iBeacon region. However, it only does so once -- if the user subsequently exits and reenters the iBeacon region, locationManager: didDetermineState does not fire again.
I'm running an iPhone 5s and using an iPhone 4s as the iBeacon, if that makes any difference.
Correction: This phenomenon is evidently only happening when I use an iPhone 4s as the client. If I use a 5s, the notification is delivered immediately.
Just trying to get more info. Have you set notifyEntryStateOnDisplay to YES on the CLBeaconRegion? It sounds like it.
From documentation:
When set to YES, the location manager sends beacon notifications when the user turns on the display and the device is already inside the region. These notifications are sent even if your app is not running. In that situation, the system launches your app into the background so that it can handle the notifications. In both situations, the location manager calls the locationManager:didDetermineState:forRegion: method of its delegate object.
The default value for this property is NO.
I had a similar issue as well and tried various code level changes detailed above (and other posts). Ranging worked but the Enter and Exit zone detection did not.
It turned out that I had App Background Refresh off. Once I enabled background app refreshing the Entering and Exiting of the zones worked correctly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With