Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CLBeaconRegion not calling didEnterRegion from termination

I have been doing some reading about CLBeaconRegion and I have setup some iBeacons successfully and had it trigger location updates, even while the application is in the background.

However, from what I've read and carry over from CLRegion, I understand that it should be possible to hit locationManager:didEnterRegion: after the application is terminated.

I've setup my CLBeaconRegion like this:

beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:[[NSUUID alloc] initWithUUIDString:SERVICE_UUID]
                                                       major:0
                                                       minor:0
                                                  identifier:BEACON_ID];
[beaconRegion setNotifyOnEntry:YES];
[beaconRegion setNotifyOnExit:YES];
[beaconRegion setNotifyEntryStateOnDisplay:YES];

But I am not able to trigger the CLLocationManager's delegate from termination. I've left the region (confirmed by a notification), travelled further away from the beacon, waited for 30 seconds, then travelled back to the beacon, but it does not trigger the delegate while terminated (works great while in the background and foreground).

Should this work from termination? Am I missing something? Any help would be great.

like image 228
RileyE Avatar asked Oct 22 '13 23:10

RileyE


3 Answers

I believe that when you are in the background or not running, it calls locationManager:didDetermineState:forRegion: instead of locationManager:didEnterRegion:, and then only if you've set notifyEntryStateOnDisplay to TRUE.

like image 71
Duncan C Avatar answered Nov 02 '22 00:11

Duncan C


This is the expected behavior on iOS 7. However, this behavior has been changed under iOS 7.1. iOS 7.1 reverts delegate calls back to pre-iOS 7 behavior.

I've documented this behavior in a blog post of mine.

http://www.simplymadeapps.com/blog/2014/03/7-1-brings-back-geofence-behavior/

like image 1
Bill Burgess Avatar answered Nov 02 '22 02:11

Bill Burgess


EDIT: The below is no longer true as of 7.1. You can still receive notifications even when the application has closed

The behavior of applications being swiped away in the application switcher now has the effect you're describing under iOS 7.

Users who remove your application from the switcher have made a decision to not allow your app to run in the background. Thus, region monitoring will not re-open your application.

Check out the "What’s New with Multitasking" session from WWDC 2013 for more information.

like image 1
mattyohe Avatar answered Nov 02 '22 01:11

mattyohe