Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can [LocationManager didEnterRegion] Get a Beacon's Major & Minor?

I got a few beacons from Roximity and from what I have gathered, ALL Roximity beacons have the same UUID. I know that I can get the major and minor values using [locationManager: didRangeBeacons: inRegion:] but if I setup [locationManager didEnterRegion] to send a push notification, and my user walks by a different Roximity beacon, that is associated with someone else's app, how can I determine this in [locationManager didEnterRegion] ?

like image 446
Chris Avatar asked Jan 20 '14 22:01

Chris


1 Answers

You basically have two choices.

  1. Define the regions that you are monitoring so they include your specific major and minor numbers. The main limitation is that iOS only lets you monitor 20 regions simultaneously, meaning you can only do this for 20 different iBeacons:

    CLBeaconRegion *region1 = [[CLBeaconRegion alloc] initWithProximityUUID:[[NSUUID alloc] initWithUUIDString:@"8deefbb9-f738-4297-8040-96668bb44281"] major:1201 minor:3211 identifier:@"beacon1"];    
    [_locationManager startRangingBeaconsInRegion:region1];    
    CLBeaconRegion *region1 = [[CLBeaconRegion alloc] initWithProximityUUID:[[NSUUID alloc] initWithUUIDString:@"8deefbb9-f738-4297-8040-96668bb44281"] major:1798 minor:2122 identifier:@"beacon2"];    
    [_locationManager startRangingBeaconsInRegion:region2];
    ...
    
  2. Monitor a Region based only on the UUID, but also do Ranging on this same Region simultaneously. You will get Ranging callbacks for every specific iBeacon you see. (Even in the background you will get this for about 5 seconds after entering the Region.) In the Ranging callback, you check the major/minor numbers of the beacons you see and compare them to a list of the ones you own. Only if you see a match do you perform a specific action. Keeping this list up-to-date in your app might be difficult if you keep adding beacons, so you might want to use a web service like ProximityKit that lets you store your list of iBeacon identifiers in the cloud.

    -(void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region {
       for (CLBeacon *beacon in beacons) {
         if ([self isMyBeaconWithMajor: beacon.major minor: beacon.minor]) {
            // Yes, this is my beacon!  Do something special here
         }
       }
    }
    
    -(BOOL)isMyBeaconWithMajor: (NSNumber *)major minor: (NSNumber *)minor {
      // TODO: write code here that returns YES if the major and minor belong to you
    }
    

Another final possibility (admittedly a bit outside what you are asking) is to use beacons with a custom UUID, which makes things a lot easier. Full disclosure: I am an employee a company that sells iBeacons with customizable identifiers.

like image 66
davidgyoung Avatar answered Nov 14 '22 05:11

davidgyoung