3

这是我使用 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 设备。但是对于第三方应用程序,它发现很好。

添加图像证明它是 Eddystone 信标

我做错了什么?

4

1 回答 1

2

您的代码正在使用核心位置,它仅适用于 iBeacon。您将无法通过这种方式发现 Eddystone 信标。

您需要使用一些与 Eddystone 兼容的 SDK。由于您似乎在使用 Kontakt.io 的信标,您可能想要使用他们的 SDK:

http://developer.kontakt.io/ios-sdk/quickstart/#eddystone-support

或者,您也可以使用 iOS 原生的 Core 蓝牙自行实现 Eddystone 扫描。官方 Eddystone GitHub 存储库中甚至还有一个关于如何做到这一点的示例:

https://github.com/google/eddystone/tree/master/tools/ios-eddystone-scanner-sample

于 2015-12-14T13:45:34.343 回答