简体   繁体   English

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

[英]iBeacon: didRangeBeacons is not getting called when running app

I prepared all the necessary stuff to setup a beacon region: 我准备了设置信标区域所需的所有东西:

// 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];

However, didRangeBeacons is not always invoked. 但是,并不总是调用didRangeBeacons。 It invokes only once but then stops getting invoked. 它只调用一次,但后来停止调用。

Are you sure that didRangeBeacons was invoked even once? 你确定曾经调用过didRangeBeacons吗? It will not be invoked if you just call startMonitoringForRegion . 如果只调用startMonitoringForRegion ,则不会调用它。 When you call startMonitoringForRegion you should get callback in your locationManager's delegate object in the form of didDetermineState , didEnterRegion and didExitRegion . 当你调用startMonitoringForRegion你应该以didDetermineStatedidEnterRegiondidExitRegion的形式在你的locationManager的委托对象中得到回调。 What you need to do is, in your didEnterRegion method, call startRangingBeaconsInRegion . 您需要做的是,在您的didEnterRegion方法中,调用startRangingBeaconsInRegion Here is an example: 这是一个例子:

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

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

Also dont forget to stop ranging: 也别忘了停止测距:

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

        //STOP ranging
        [_locationManager stopRangingBeaconsInRegion:beaconRegion];
    }
}

Only if you start ranging, your didRangeBeacons will be invoked. 只有在开始测距时,才会调用didRangeBeacons

Hope this helps. 希望这可以帮助。

Try following code: 请尝试以下代码:

// 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];

You need to start ranging beacons as well to make didRangebeacons to be called. 你需要开始测距信标,以便调用didRangebeacons。

Are you only seeing this with your Raspberry Pi-based beacon? 你只用基于Raspberry Pi的灯塔看到这个吗? If so, your Pi's advertisements may be getting turned off by another device attempting to connect with it. 如果是这样,您的Pi的广告可能会被试图与之连接的其他设备关闭。 The Knock app for OSX is known to cause this problem , although other apps may do it, too. 已知OSX的Knock应用程序会导致此问题 ,但其他应用程序也可能会这样做。

If this is the problem, there is a fix documented in an edit to the blog post telling you how to build an iBeacon out of a Raspberry Pi. 如果这是问题,那么在博客文章的编辑中会记录一个修复,告诉您如何从Raspberry Pi构建iBeacon。 You need to edit the iBeacon start script on the Pi to change this line: 您需要在Pi上编辑iBeacon启动脚本以更改此行:

sudo hciconfig $BLUETOOTH_DEVICE leadv 0

to: 至:

sudo hciconfig $BLUETOOTH_DEVICE leadv 3

Alternatively, you can try simply shutting off whatever app is running that is trying to establish a Bluetooth LE connection to the Raspberry Pi. 或者,您可以尝试简单地关闭正在尝试建立与Raspberry Pi的蓝牙LE连接的正在运行的应用程序。 If you don't know what app is doing that, though, this may be hard. 但是,如果你不知道应用程序在做什么,这可能很难。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 iBeacon:didRangeBeacons没有被调用 - iBeacon: didRangeBeacons not being called iBeacon:didRangeBeacons不再被呼叫,必须重置设备才能使其再次工作 - iBeacon: didRangeBeacons stops getting called, must reset device for it to work again 当显示为关闭时,不会调用didRangeBeacons方法 - didRangeBeacons method not getting called when display is Off 应用程序未运行时的iBeacon通知 - iBeacon Notification when the app is not running 在没有iBeacon的情况下实现地理围栏时,当应用未运行时,didEnterRegion和didDetermineState不被调用 - didEnterRegion & didDetermineState not being called when the app is not running while implementing Geofencing without iBeacon 应用程序在区域中启动时,iBeacon - didEnterRegion未被调用 - iBeacon - didEnterRegion not being called when app starts in region didRangeBeacons无法在iOS中获取uuid - didRangeBeacons not getting uuid in ios locationManager的'didExitRegion'没有被称为iBeacon Xcode - locationManager 'didExitRegion' not getting called iBeacon Xcode 当app在后台时,使用iBeacon进行广告宣传 - Advertising with iBeacon when app is in background 即使信标关闭,didRangeBeacons也被称为 - didRangeBeacons is called even beacon is off
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM