Reputation: 1759
I am trying to add iBeacon support to my app. I don't have any physical iBeacons, so I am using the Locate app from Radius Networks on another iPhone. With that app I am able to see the other phones beacons. However, in my own app didRangeBeacons never gets called. I made sure to add the CoreLocation and CoreBluetooth frameworks to my app. Any ideas?
Here is the code that I have:
- (instancetype)init
{
self = [super init];
if (self)
{
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
self.discoveryUUID = [[NSUUID alloc] initWithUUIDString:@"E2C56DB5-DFFB-48D2-B060-D0F5A71096E0"];
self.region = [[CLBeaconRegion alloc] initWithProximityUUID:self.discoveryUUID identifier:[self.discoveryUUID UUIDString]];
[self.locationManager startRangingBeaconsInRegion:self.region];
self.timer = [[NSTimer alloc] initWithFireDate:[NSDate dateWithTimeIntervalSinceNow:LocatorTimeInSec] interval:0 target:self selector:@selector(timerElapsed:) userInfo:nil repeats:NO];
[[NSRunLoop currentRunLoop] addTimer:self.timer forMode:NSDefaultRunLoopMode];
}
return self;
}
-(void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region
{ ... }
Upvotes: 3
Views: 1081
Reputation: 417
Make sure to turn on Bluetooth on your the device you're debugging on.
Upvotes: 2
Reputation: 1759
Ok, I was missing the following in the app-Info.plist file. I guess for iOS 8 you need it...
<key>NSLocationWhenInUseUsageDescription</key>
<string>This will allow you to...</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>This will allow you to...</string>
And I need to add the following code:
if([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)])
{
[self.locationManager requestAlwaysAuthorization];
}
Upvotes: 2
Reputation: 1564
You will need to add:
self.region.notifyOnEntry = YES;
Optionally, you can also add for notifications when display is on:
self.region.notifyEntryStateOnDisplay = YES;
Upvotes: 0