问题
Here is a code I use to detect Eddystone using iPhone iOS 9:
- (void)viewDidLoad
{
[super viewDidLoad];
if ([CLLocationManager locationServicesEnabled]) {
_locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
self.locationManager.pausesLocationUpdatesAutomatically = NO;
[self.locationManager requestAlwaysAuthorization];
NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:@"f7826da6-4fa2-4e98-8024-bc5b71e0893e"];
NSString *bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];
CLBeaconRegion *beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:uuid identifier:bundleIdentifier];
self.locationManager.allowsBackgroundLocationUpdates = YES;
[self.locationManager startMonitoringForRegion:beaconRegion];
[self.locationManager startRangingBeaconsInRegion:beaconRegion];
[self.locationManager startUpdatingLocation];
}
else {
NSLog(@"location service is disabled");
}
}
- (void)locationManager:(CLLocationManager *)manager
didRangeBeacons:(nonnull NSArray<CLBeacon *> *)beacons
inRegion:(nonnull CLBeaconRegion *)region
{
NSLog(@"beacons count: %lu", (unsigned long)[beacons count]); // beacons count always "0"
}
Also I added in plist NSLocationAlwaysUsageDescription field.
The problem is that it can't detect any Eddystone device with code above. But with third party apps it finds well.
What I'm doing wrong?
回答1:
Your code is using Core Location, which only works with iBeacon. You won't be able to discover Eddystone beacons this way.
You need to use some Eddystone-compatible SDK. Since you seem to be using Kontakt.io's beacons, you might want to use their SDK:
http://developer.kontakt.io/ios-sdk/quickstart/#eddystone-support
Alternatively, you can use iOS's native Core Bluetooth to implement Eddystone scanning yourself. There's even an example on how to do that, available in the official Eddystone GitHub repo:
https://github.com/google/eddystone/tree/master/tools/ios-eddystone-scanner-sample
来源:https://stackoverflow.com/questions/34240751/eddystone-beacon-detecting-issue