I am trying to get the "major" and "minor" id from the beacon that triggers a didEnterRegion method. I have been told that I can do this by combining ranging and monitoring together, but I cant seem to get it working right.
I am using the Estimote beacons and am using the Estimote API. Any ideas whats going wrong here? Thanks!
Here's a link to where it says you can combine monitoring and ranging: iBeacon: get major and minor - only looking for uuid
Setup:
#import "ViewController.h"
#import "ESTBeaconManager.h"
@interface ViewController () <ESTBeaconManagerDelegate>
@property (nonatomic, strong) ESTBeaconManager* beaconManager;
@property (nonatomic, strong) UIImageView* bgImageView;
@property (nonatomic, assign) BOOL notificationShown;
@property (nonatomic, strong) UIImageView* productImage;
@end
@implementation ViewController
ViewDidLoad:
- (void)viewDidLoad
{
[super viewDidLoad];
self.beaconManager = [[ESTBeaconManager alloc] init];
self.beaconManager.delegate = self;
self.beaconManager.avoidUnknownStateBeacons = YES;
ESTBeaconRegion* region = [[ESTBeaconRegion alloc]
initRegionWithIdentifier:@"EstimoteSampleRegion"];
[self.beaconManager startMonitoringForRegion:region];
[self.beaconManager requestStateForRegion:region];
[self.beaconManager startRangingBeaconsInRegion:region];
[[NSUserDefaults standardUserDefaults] setObject:@"FALSE"
forKey:@"connectedToBeacon"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
DidRangeBeacons:
-(void)beaconManager:(ESTBeaconManager *)manager
didRangeBeacons:(NSArray *)beacons
inRegion:(ESTBeaconRegion *)region {
NSString *connectedToBeacon = [[NSUserDefaults standardUserDefaults]
stringForKey:@"connectedToBeacon"];
if (connectedToBeacon == FALSE) {
NSNumber *beaconMajor = region.major;
NSNumber *beaconMinor = region.minor;
NSString *alertText = [NSString stringWithFormat:@" Entering (%@,%@)",
beaconMajor, beaconMinor];
UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.alertBody = alertText;
notification.soundName = UILocalNotificationDefaultSoundName;
[[UIApplication sharedApplication] presentLocalNotificationNow:notification];
[[NSUserDefaults standardUserDefaults] setObject:@"TRUE"
forKey:@"connectedToBeacon"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
}