下面是使用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设备。但有了第三方应用程序,它找到了很好的服务。
我做错什么了?
发布于 2015-12-14 13:45:34
您的代码使用的是,它只适用于iBeacon。你不可能这样发现埃迪斯通的信标。
您需要使用一些与Eddystone兼容的SDK。由于您似乎在使用Kontakt.io的信标,您可能需要使用它们的SDK:
http://developer.kontakt.io/ios-sdk/quickstart/#eddystone-support
或者,您可以使用iOS的本机核心蓝牙来实现Eddystone自己扫描。甚至还有一个关于如何做到这一点的例子,可以在官方的Eddystone GitHub回购中获得:
https://github.com/google/eddystone/tree/master/tools/ios-eddystone-scanner-sample
https://stackoverflow.com/questions/34240751
复制相似问题