Mobile Line Of Business

Richard Jones (MVP)

  Home  |   Contact  |   Syndication    |   Login
  202 Posts | 0 Stories | 36 Comments | 0 Trackbacks


Welcome to the Mobile Line Of Business Blog

Tag Cloud


Post Categories



So cakes are an issue in our office.     We have two offices one in the UK one in the US.   When someone has a birthday an allusers email gets sent out that cakes are in the office.    This inevitably leads to crushing disappointment when you happen to be in the other office to where the cakes are.

So the cake issue was one of the reasons we needed a reliable in/out board to show exactly who’s in each office and the ability to send a targeted email to just the office we are trying to reach.   Of course we could have put this on a white/board or purchased something more elaborate. 

I should point out, that the intentions of this project were no more sinister than reliably maintaining a list of ‘who’s in’   this wasn’t intended as attendance recording or anything like that.

So how do you record who’s in the office automatically?    Who’s logged onto the network?   Which machines have been assigned a DHCP address or using the WIFI?   All possible,  but all have their difficulties in implementing and have questionable reliability for actually determining who’s in.     Of course you could go the other way and make people visit a web-page to indicate their in;  but realistically who is going todo that.

So the majority of our users have our office mobile portal app. running on their iPhone.   This app. has a phone list;  what was required is filter to reduce this list down to just who’s in the office.   So how do we determine just who’s in?


The solution was to equip each office location with an iBeacon.      I thought about using a Raspberry Pi, or a PC acting as a Bluetooth low energy beacon,  however the simplest and cheapest solution was to purchase an off the shelf beacon.

I opted for a £12 beacon from Amazon that could be placed centrally in each office location.

These things are tiny any run for 6 months on a watch battery with an estimated range of 40m.   Impressive stuff; and a bargain at the price.



So when our Beacons arrived the first thing todo was program them with a unique identifier that our mobile app. would look out for.   This was done by downloading an app. (called eBeacon on the app store).  This app discovered our new beacons and we were able to assign them a unique ID of our choosing.

I opted to give each Beacon a different ID.   This made the coding changes a little easier (more of that in a bit),  as it just let me monitor for beacons, which I could do in the background.

I placed each beacon centrally in the office and with a little testing using the eBeacon app.  I was able to reliably record that I was in proximity of the beacon from pretty much any part of the office.

So with Beacon’s installed,  it was time to modify our App. 



Our mobile portal App. is written in Objective C (process is the same in Swift).   I needed to modify the ApplicationDidFinishLaunching method to monitor for each beacon.    This process is well documented elsewhere, but briefly I had to register that my app.  required always authorisation to request a users location.   Again this sounds a bit sinister but its just for the purpose of determining if we are near a beacon when our app. isn’t running.   To achieve this I added the following code - 

self.locationmanager=[[CLLocationManager alloc] init];
[self.locationmanager requestAlwaysAuthorization];
[self.locationmanager requestWhenInUseAuthorization];

You also need to make sure that your app responds to the Location Manager Delegate which just required adding the delegate CLLocationManagerDelegate on the end our app delegate definition as follows -

@interface Mobile_Portal_v2AppDelegate : NSObject

In iOS 8 you need to also alter your apps xxxx.Plist file to add two new keys that give's the end user a nice friendly message that your app. is requesting background location updates and what the purpose of this is. These are -


I set these bot the be, "Our Office App, Is Requesting Your Location; Do You wish to allow this?"

so the next bit of code is to actually tell the App. to look out for each beacon. Realistically once you have come into proximity of the beacon it was quite possible to go sit at your desk and be out of range. So without doing anything more elaborate I decided for this project, it was good enough to just record that a person had visited the office in a given day; I didn't intend to record they had left; I just assumed you would leave the office at some point during a working day. So again adding to the ApplicationDidFinishLaunching method, I put some code in to monitor for when we are near our beacon

NSUUID *uuidh = [[NSUUID alloc] initWithUUIDString:@“GUID OF BEACON HERE"];
CLBeaconRegion *regionh = [[CLBeaconRegion alloc] initWithProximityUUID:uuidh identifier:@"COM.XXXX.LOCATION"];

 regionh.notifyOnEntry = YES;
 self.locationmanager startMonitoringForRegion:regionh];

nothandler = [NotificationHandler alloc];

So this tells our app. to listen out for arriving at a Beacon. I duplicated this code for each office location. As mentioned earlier I assigned each Beacon a different ID. This made my code simpler as I just needed to monitor beacons, I didn't need to determine range from them. Ranging gives us access to a major and minor value on each beacon; but it was easier just to assign different unique identifiers which was fine for my purposes.

What Happens When You Arrive?

So the next bit of code was to actually determine what todo when our app. detected it was in proximity of a given beacon. This method was added to our AppDelegate

- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
 // I've been notified by a beacon
 if ([region isKindOfClass:[CLBeaconRegion class]]==NO) return;
 CLBeaconRegion *ourbeaconregion=(CLBeaconRegion *) region;

 // get which user am I
 NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
 [prefs synchronize];
 NSString *user = [prefs stringForKey:@"user"];

 if (user==nil) return;

 NSString *bec=[ourbeaconregion.proximityUUID UUIDString];
 // call a web-service to record the arrival
  [hitbeacon run:user beacon:bec];

So the nuts and bolts of this determine, which user we are, and the GUID of the beacon we have arrived at.

Once we have these two bits of information I make a web-service call to alert our server that we have arrived...

You've Arrived

So our server records (using a web service) for a given user when they have arrived in a given location into a database table. I created a view on top of this, which shows for a given date all arrivals (this data is over-written, daily so never retained.

The Cake Solution

The final piece was to create a web-page that reads from the above view to create a filtered list of who's in each office location. In addition using the list of people I added a mailto: link which creates an email for just those who are in.

posted on Monday, September 7, 2015 4:36 AM