Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
//
// IDViewController.m
// MyFirstIndoorsApp
//
// Copyright (c) 2013 indoo.rs GmbH. All rights reserved.
//
#import "IDViewController.h"
#import <CoreLocation/CoreLocation.h>
@interface IDViewController () <CLLocationManagerDelegate>
@property (strong, nonatomic) CLLocationManager *locationManager;
@end
@implementation IDViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// background modes do not affect ibeacon-behavior
// http://developer.radiusnetworks.com/2013/11/13/ibeacon-monitoring-in-the-background-and-foreground.html
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
CLBeaconRegion *region = [[CLBeaconRegion alloc] initWithProximityUUID:[[NSUUID alloc]
initWithUUIDString:@"EC9A4B41-C534-4719-9634-D2E871A3B076"] identifier:@"indoo.rs office"];
// if YES, didEnter / didExit will ALWAYS be called if you turn on the screen (even without unlocking!)
// region.notifyEntryStateOnDisplay = YES;
[self.locationManager startMonitoringForRegion:region];
[self.locationManager startRangingBeaconsInRegion:region];
}
#pragma mark CLLocationManagerDelegate
- (void)locationManager:(CLLocationManager *)manager
didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region
{
// called for 5-10 seconds after didEnter / didExit has been called
// always called if you turn on the screen (even without unlocking!)
NSLog(@"didRange");
}
- (void)locationManager:(CLLocationManager *)manager
didEnterRegion:(CLRegion *)region
{
// called when you enter a region - even if the screen is completely turned off!
// called with a huge delay (up to 15 minutes!) if the screen is completely turned off
// http://developer.radiusnetworks.com/2013/11/13/ibeacon-monitoring-in-the-background-and-foreground.html
NSLog(@"didEnter");
}
- (void)locationManager:(CLLocationManager *)manager
didExitRegion:(CLRegion *)region
{
// called when you leave a region - even if the screen is completely turned off!
// called with a huge delay (up to 15 minutes) if the screen is completely turned off
// http://developer.radiusnetworks.com/2013/11/13/ibeacon-monitoring-in-the-background-and-foreground.html
NSLog(@"didExit");
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.