这是我使用iPhone iOS 9检测Eddystone的代码:
- (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"
}
我也添加了plist NSLocationAlwaysUsageDescription字段。
问题在于它无法检测到具有以上代码的任何Eddystone设备。但是使用第三方应用程序,它的效果很好。
我做错了什么?
最佳答案
您的代码使用的是Core Location,仅与iBeacon一起使用。您将无法通过这种方式发现Eddystone信标。
您需要使用一些与Eddystone兼容的SDK。由于您似乎正在使用Kontakt.io的信标,因此您可能要使用其SDK:
http://developer.kontakt.io/ios-sdk/quickstart/#eddystone-support
另外,您可以使用iOS的本机Core Bluetooth自己实施Eddystone扫描。甚至在官方Eddystone GitHub存储库中提供了有关如何执行此操作的示例:
https://github.com/google/eddystone/tree/master/tools/ios-eddystone-scanner-sample