iBeacon:在运行应用程序时,没有调用didRangeBeacons

时间:2013-12-14 20:05:44

标签: ios raspberry-pi locationmanager ibeacon

我准备了设置信标区域所需的所有东西:

// Create a NSUUID with the same UUID as the broadcasting beacon
NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:@"E2C56DB5-DFFB-48D2-B060-D0F5A71096E0"];
//raspberry pi:E2C56DB5-DFFB-48D2-B060-D0F5A71096E0
//estimote:B9407F30-F5F8-466E-AFF9-25556B57FE6D

// Setup a new region with that UUID and same identifier as the broadcasting beacon
self.myBeaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:uuid
                                                                identifier:@"monaLisaBeacon"];

// Tell location manager to start monitoring for the beacon region
[self.locationManager startMonitoringForRegion:self.myBeaconRegion];

但是,并不总是调用didRangeBeacons。它只调用一次,但后来停止调用。

3 个答案:

答案 0 :(得分:2)

您确定曾经调用过didRangeBeacons吗?如果您只是致电startMonitoringForRegion,则不会调用它。当您致电startMonitoringForRegion时,您应该以{{1​​}},didDetermineStatedidEnterRegion的形式在locationManager的委托对象中进行回调。您需要做的是,在didExitRegion方法中,拨打didEnterRegion。这是一个例子:

startRangingBeaconsInRegion

也不要忘记停止测距:

- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region {
    if ([region isKindOfClass:[CLBeaconRegion class]]) {
        CLBeaconRegion *beaconRegion = (CLBeaconRegion *)region;

        //now start ranging
        [_locationManager startRangingBeaconsInRegion:beaconRegion];
    }
}

只有在您开始测距时,才会调用- (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region { if ([region isKindOfClass:[CLBeaconRegion class]]) { CLBeaconRegion *beaconRegion = (CLBeaconRegion *)region; //STOP ranging [_locationManager stopRangingBeaconsInRegion:beaconRegion]; } }

希望这有帮助。

答案 1 :(得分:2)

请尝试以下代码:

// Create a NSUUID with the same UUID as the broadcasting beacon
NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:@"E2C56DB5-DFFB-48D2-B060-D0F5A71096E0"];
//raspberry pi:E2C56DB5-DFFB-48D2-B060-D0F5A71096E0
//estimote:B9407F30-F5F8-466E-AFF9-25556B57FE6D

// Setup a new region with that UUID and same identifier as the broadcasting beacon
self.myBeaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:uuid
                                                                identifier:@"monaLisaBeacon"];

// Tell location manager to start monitoring for the beacon region
[self.locationManager startMonitoringForRegion:self.myBeaconRegion];
[self.locationManager startRangingBeaconsInRegion:beaconRegion];

你需要开始测距信标,以便调用didRangebeacons。

答案 2 :(得分:0)

你只是在基于Raspberry Pi的灯塔上看到这个吗?如果是这样,您的Pi的广告可能会被试图与之连接的其他设备关闭。 The Knock app for OSX is known to cause this problem,虽然其他应用也可以这样做。

如果这是问题,那么blog post的编辑中会记录一个修复程序,告诉您如何从Raspberry Pi构建iBeacon。您需要在Pi上编辑iBeacon启动脚本以更改此行:

sudo hciconfig $BLUETOOTH_DEVICE leadv 0

为:

sudo hciconfig $BLUETOOTH_DEVICE leadv 3

或者,您可以尝试简单地关闭正在尝试建立与Raspberry Pi的蓝牙LE连接的正在运行的应用程序。但是,如果你不知道应用程序在做什么,那可能很难。