Reputation: 54212
I use Apple AirLocate demo App to create an iBeacon.
The signal is successfully picked up by an Android beacon detector App.
However, when I use the following codes to detect the iBeacon in iOS 8, the beacon does not show up:
self.coreLocation = [[CLLocationManager alloc] init];
_coreLocation.delegate = self;
NSString *identifier = [NSString stringWithFormat:@"com.example.apple-samplecode.AirLocate.%@", @"E2C56DB5-DFFB-48D2-B060-D0F5A71096E0"];
CLBeaconRegion *region = [[CLBeaconRegion alloc] initWithProximityUUID:uuid identifier:identifier];
if(region) {
region.notifyOnEntry = YES;
region.notifyOnExit = YES;
[_coreLocation startMonitoringForRegion:region];
}
No matter which value I use in the identifier field, the beacon is never found by CLLocationManager
. Its delegates, didDetermineState:
and didRangeBeacons:
were never been called. However, delegate monitoringDidFailForRegion
received this:
The operation couldn’t be completed. (kCLErrorDomain error 4.)
After looked up some documentations online, the error code 4 means:
Access to the region monitoring service was denied by the user.
But I use the following codes to prove my app is authorized to monitor region:
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
if(status == kCLAuthorizationStatusDenied) {
NSLog(@"didChangeAuthorizationStatus: Denied");
} else if(status == kCLAuthorizationStatusNotDetermined) {
NSLog(@"didChangeAuthorizationStatus: Not Determined");
} else if(status == kCLAuthorizationStatusAuthorizedAlways) {
NSLog(@"didChangeAuthorizationStatus: Authorized Always");
} else if(status == kCLAuthorizationStatusAuthorizedWhenInUse) {
NSLog(@"didChangeAuthorizationStatus: Authorized When In Use");
} else if(status == kCLAuthorizationStatusRestricted) {
NSLog(@"didChangeAuthorizationStatus: Restricted");
} else {
NSLog(@"didChangeAuthorizationStatus: Unknown");
}
}
and it returns:
didChangeAuthorizationStatus: Authorized When In Use
Given that:
NSLocationWhenInUseUsageDescription
in Info.plist
Info.plist
)[self.coreLocation requestWhenInUseAuthorization]
[CLLocationManager isMonitoringAvailableForClass:[CLRegion class]]
returns YESWhat did I miss to cause this error 4 ? Also, does the identifier necessary to match with the iBeacon's Bundle Identifier (why Android can detect all beacons, but iOS need to specify identifiers)?
Reference: Region Monitoring and iBeacon
Upvotes: 0
Views: 1886
Reputation: 64941
A couple of suggestions:
Try an off the shelf iOS detector from the AppStore like Locate to eliminate a hardware issue.
If the above works, try uninstalling and reinstalling your app. I have seen the location permission get screwed up if the authorization code was added after the app was already run.
Also, it may be helpful to post your Info.plist in case there is an issue there.
Upvotes: 1