Search code examples
iosibeaconestimoteestbeaconmanager

Background Notification from Beacon iOS using ESTBeaconManager


Following is my code which is detecting the beacon, but when in background it does not send notification. Can anyone trace what exactly is the problem with the code

@property (nonatomic) ESTBeaconManager *beaconManager;
@property (strong, nonatomic) CLBeaconRegion *beacRegion;
@property (strong, nonatomic) NSArray *estimoteBeacons;
- (void)viewDidLoad {
 self.beaconManager = [ESTBeaconManager new];
self.beaconManager.delegate = self;
self.beaconManager.returnAllRangedBeaconsAtOnce = YES;


 self.beacRegion = [[CLBeaconRegion alloc] initWithProximityUUID:[[NSUUID alloc] initWithUUIDString:@"xxxxxx-xxxx-xxxx-xxxx-..."] major:000 minor:0000 identifier:[NSString stringWithFormat:@"%@", @"HEY GUYS!"]];
    [self.beaconManager startRangingBeaconsInRegion:self.beacRegion];
[self.beaconManager startMonitoringForRegion:self.beacRegion];

}

- (void)beaconManager:(id)manager didEnterRegion:(CLBeaconRegion *)region
{
NSLog(@"didEnterRegion");
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.alertBody = @"You have entered the region you are monitoring";
localNotification.soundName =  UILocalNotificationDefaultSoundName;
[[UIApplication sharedApplication]presentLocalNotificationNow:localNotification];}

    - (void)beaconManager:(id)manager didEnterRegion:(CLBeaconRegion *)region
{
NSLog(@"didEnterRegion");
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.alertBody = @"You have left the region you are monitoring";
localNotification.soundName =  UILocalNotificationDefaultSoundName;
[[UIApplication sharedApplication]presentLocalNotificationNow:localNotification];}

I get this message when I see the stack trace of device:

"-iPhone ESTBeacon[1366] : monitoringDidFailForRegion Insufficient Location Services authorization. Monitoring will pause until appropriate authorization is granted."

Though I have added requestWhenInUseAuthorization in info plist


Solution

  • I suspect your app has not been granted location permissions. To verify, go to Settings -> and check to see if your app has "Always" location permission. If it does, it should look like the screenshot below.

    If you do not have location access granted, check your code that requests it. In addition to an entry in your plist, you need something like this:

    if([locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
      [locationManager requestAlwaysAuthorization];
    }
    

    enter image description here