【问题标题】:iBeacon: didRangeBeacons is not getting called when running appiBeacon:运行应用程序时没有调用 didRangeBeacons
【发布时间】:2013-12-14 20:05:43
【问题描述】:

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

// 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 并不总是被调用。它只调用一次,然后停止被调用。

【问题讨论】:

    标签: ios raspberry-pi locationmanager ibeacon


    【解决方案1】:

    你确定didRangeBeacons 被调用过一次吗?如果您只是调用startMonitoringForRegion,它将不会被调用。当您调用startMonitoringForRegion 时,您应该在您的locationManager 的委托对象中以didDetermineStatedidEnterRegiondidExitRegion 的形式获得回调。您需要做的是,在您的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];
        }
    }
    

    只有当您开始测距时,您的 didRangeBeacons 才会被调用。

    希望这会有所帮助。

    【讨论】:

      【解决方案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。

      【讨论】:

        【解决方案3】:

        您是否仅在基于 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 连接。但是,如果您不知道是什么应用程序在执行此操作,那么这可能会很困难。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2014-02-28
          • 2013-10-08
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多