Last active
December 31, 2015 13:29
-
-
Save StuffAndyMakes/7993582 to your computer and use it in GitHub Desktop.
iOS 7 iBeacon partial example (implementation)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #import "iBeaconSample.h" | |
| @implementation iBeaconSample | |
| // your other code goes here, maybe... | |
| - (void)initRegion { | |
| // Set a proximityUUID | |
| // On a Mac in the Terminal, you can use the uuidgen command to get a UUID | |
| NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:@"B9A12659-5E36-4B1D-939C-15A413F94FCE"]; | |
| // setup a region for the proximityUUID | |
| self.beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:uuid identifier:@"com.yourcompany.store123"]; | |
| // ask for certain types of notifications | |
| self.beaconRegion.notifyEntryStateOnDisplay = YES; | |
| self.beaconRegion.notifyOnEntry = YES; | |
| self.beaconRegion.notifyOnExit = YES; | |
| // start watching for beacons | |
| [self.locationManager startRangingBeaconsInRegion:self.beaconRegion]; | |
| } | |
| - (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region { | |
| // do something here with your notification | |
| } | |
| - (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region { | |
| // do something here with your notification | |
| } | |
| -(void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beaconsFound inRegion:(CLBeaconRegion *)region { | |
| /* | |
| What the beacons array looks like: | |
| ( | |
| "CLBeacon (uuid:<__NSConcreteUUID 0x178038e80> B9A12659-5E36-4B1D-939C-15A413F94FCE, major:1255, minor:65, proximity:0 +/- -1.00m, rssi:0)", | |
| "CLBeacon (uuid:<__NSConcreteUUID 0x178038f80> B9A12659-5E36-4B1D-939C-15A413F94FCE, major:1255, minor:67, proximity:2 +/- 0.84m, rssi:-44)", | |
| "CLBeacon (uuid:<__NSConcreteUUID 0x1780390c0> B9A12659-5E36-4B1D-939C-15A413F94FCE, major:1255, minor:66, proximity:3 +/- 5.93m, rssi:-57)" | |
| ) | |
| */ | |
| // Do something useful with the list of beacons | |
| } | |
| @end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment