Search code examples
iosobjective-cibeacon

iBeacon and Notification


i'm developing an iOS application and i'm using beacons.

I've a problem. I'm at the beginning of the development, so I only have my appdelegate. In appdelegate.m I have initialized like so

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.

    self.locationManager = [[CLLocationManager alloc] init];
    self.locationManager.delegate = self;

    NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:@"8AEFB031-6C32-486F-825B-E26FA193487D"];
    CLBeaconRegion *region = [[CLBeaconRegion alloc] initWithProximityUUID:uuid
                                                                identifier:@"Region"];

    if ([CLLocationManager isMonitoringAvailableForClass:[CLBeaconRegion class]])
    {
        NSLog(@"I'm looking for a beacon");
        [self.locationManager startRangingBeaconsInRegion:region];
    } else {
        NSLog(@"Device doesn't support beacons ranging");
    }

    return YES;
}

and then I wrote two delegate methods

- (void) locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region {
    NSLog(@"EXIT");
}

- (void) locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region {
    NSLog(@"ENTER");
}

but they never get called!!! What's the problem here?


Solution

  • you RANGE but you never MONITOR the regions.

    Ranging for beacons will only call:
    locationManager:didRangeBeacons:inRegion:

    The methods enterRegion/exitRegion you want are for monitoring only. So call:
    - (void)startMonitoringForRegion:(CLRegion *)region