I managed to get local notification when iBeacon (using Kontakt Beacon) enter a region in Background mode . at the same time I monitor 3 beacon regions with specific & u
CoreLocation is known to be fairly unstable with notifications both when monitoring regions and ranging beacons. We had to implement a similar filter to ranging notifications in our sample app, the source code is at https://github.com/BlueSenseNetworks/iOS
Basically the app keeps a circular buffer with the latest 10 sightings and makes a decision on what to display based on the type of the majority of sightings.
It is not uncommon for CoreLocation to periodically have a "glitch" and send you a notification saying you exited the region and then a second later say you entered that same region.
Without seeing your code, it's hard to say for certain that this is what happening, but if it is, you can fix this easily enough by adding a software filter on your exit and enter events. You basically ignore an exit event if an entry event happened for the same region within the previous few seconds. Likewise, you ignore an entry event if an exit event for the same region happened within the previous few seconds.
In order to do this you need to keep two tables, one that contains the most recent entry events keyed by region, and on that contains the most recent exit events keyed by region.
Here's an example of code to put at the top of a didEnterRegion callback method that uses a class-level NSMutableDictionary called _enteredTimes as a lookup table to accomplish this:
NSDate *now = [[NSDate alloc] init];
CLBeaconRegion *beaconRegion = (CLBeaconRegion *) region;
NSString *regionKey = [NSString stringWithFormat: @"%@_%@_%@", beaconRegion.proximityUUID, beaconRegion.major, beaconRegion.minor];
NSDate *lastEntered = [_enteredTimes valueForKey:regionKey];
[_enteredTimes setValue: now forKey: regionKey];
if (lastEntered != Nil && [now timeIntervalSinceDate:lastEntered] < 10) { // last 10 secs
// ignore this event
return;
}
You have to put equivalent code in your didExitRegion callback.