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 でのみ動作する Core Location を使用しています。この方法では、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

于 2015-12-14T13:45:34.343 に答える