iBeacon Department Store Scenario - Ranging vs. Monitoring

2.4k views Asked by At

So we are trying to put together a scenario with iBeacons and I think we are getting stuck with the differences between ranging and monitoring in the background and now i'm not sure what we want to do is possible.

We have 500 stores that we want to deploy iBeacons to. The purpose of the beacon is to greet the customer with a notification and a coupon (sometimes). What we would like to do is utilize a single UUID with the major being the store number and the minor being type of store (regular store vs. kids. A kids store can be connected to a regular store). Ideally, once a iBeacon with our UUID is found, we would like our app to pull an XML file from our website specific to the major number (store number), display a notification welcome message (possibly stating 'we have a coupon for you' depending on what the xml file says), and save the xml file data to the app so the user can retrieve the coupon if they open the app. This all seems possible with the application in the foreground, but we seem to be having difficultly getting it to work in the background. Is what I am describing possible and should I be thinking of a different way to do this?

Thanks

1

There are 1 answers

3
davidgyoung On

Yes, you can do this. The trick is that you need to combine both ranging and monitoring at the same time. Monitoring is needed to launch your app into the background. Ranging is needed to get the specific ids of the Beacons you see.

Set it up like this:

CLBeaconRegion *region = [[CLBeaconRegion alloc] initWithProximityUUID:uuid identifier:@"blah"];
region.notifyOnEntry = YES;
[self.locationManager startMonitoringForRegion:region]; 
[self.locationManager startRangingBeaconsInRegion:region]; 

As soon as this happens, you will get ranging callbacks for about five seconds before the application goes back to sleep, and this method will get called once per second:

-(void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region {
    if (!_firstOneSeen) { 
      _firstOneSeen = true;
      // Do something with beacons array here.  read out the major/minor and get the 
      // notification message from your XML web service                   
   }
}

Two notes of caution:

  1. Monitoring iBeacon Regions in the background can be a little tricky, and it can take longer than you might think to get callbacks. See this detailed discussion.

  2. You only have five seconds from when your app is woken up until it goes back to sleep, so your web site better respond very quickly. A safer idea that would work across network dropouts would be to fetch the XML up front and cache it inside your app so it is ready to go even if there is a network dropout.

My company, Radius Networks makes a library and web service called ProximityKit that does this up-front caching of beacon-specific key/value pairs that you can configure with your web browser. That way, you don't have to write the web service yourself.