Eddystone 信标检测问题

Eddystone beacon detecting issue

这是我用来检测 Eddystone 的代码 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"
}

我还在 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