【问题标题】:Multiple beacons didRangeBeacons delegate call returning just one beacon at a time多个信标 didRangeBeacons 委托调用一次只返回一个信标
【发布时间】:2015-09-09 10:41:42
【问题描述】:

我正在使用 iBeacons。我有多个信标,每个信标具有相同的 UUID、主要值,但次要值不同。两个设备都有范围,但它们没有一起接收, - locationManager:didRangeBeacons:inRegion:委托回调“信标”数组一次仅包含 1 个信标。

我知道使用多个区域会分别有回调

这就是监控和测距信标的代码

// Initialize and monitor regions
for (NSString *serviceUUID in _serviceUUIDs) {
  // Initialize region
  NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:serviceUUID];
  CLBeaconRegion *appBeaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:uuid major:major minor:minor identifier:identifier];
  // Specify notifications
  appBeaconRegion.notifyEntryStateOnDisplay = YES;
  appBeaconRegion.notifyOnEntry = YES;
  appBeaconRegion.notifyOnExit = YES;
  // Add to regions
  [_appBeaconRegions addObject:appBeaconRegion];
  // Begin monitoring region and ranging beacons
  [_locationManager startMonitoringForRegion:appBeaconRegion];
  [_locationManager startRangingBeaconsInRegion:appBeaconRegion];
}

我希望在单个回调范围内拥有所有信标

如何为所有信标使用具有不同次要标识符值的单个区域

任何帮助表示赞赏..

谢谢

【问题讨论】:

    标签: ios


    【解决方案1】:

    您可以使用BeaconManagerDelegatedidFindBeacon 回调来观察附近的信标。这将获取所有具有相同 UUID 的信标。

    【讨论】:

      【解决方案2】:

      这是我为此目的编写的代码:-

      // in ApplicationdidFinishLaunchingWithOptions
          let beaconID = NSUUID(UUIDString: "ADBD15B8-9A2F-492F-BB26-C7C92E05CAD3")
                  let regionIdentifier = "humra.ibeacons"
                  let beaconRegion = CLBeaconRegion(proximityUUID: beaconID!, identifier: regionIdentifier)
                  if locationManager.respondsToSelector("requestAlwaysAuthorization")
                  {
                      locationManager.requestAlwaysAuthorization()
                  }
                  locationManager.delegate=self
                  locationManager.pausesLocationUpdatesAutomatically=false
                  locationManager.startMonitoringForRegion(beaconRegion)
                  locationManager.startRangingBeaconsInRegion(beaconRegion)
                  locationManager.startUpdatingLocation()
      
      
              func locationManager(manager: CLLocationManager, didRangeBeacons beacons: [CLBeacon], inRegion region: CLBeaconRegion) {
                  NSLog("didRangeBeacons");
                  let message:String = ""
      
                  if(beacons.count > 0) {
                      let nearestBeacon:CLBeacon = beacons[0] as CLBeacon
                      closestBeacon=nearestBeacon
      
                  } else {
          //            message = "No beacons are nearby"
                  }
      
                  NSLog("%@", message)
                  sendLocalNotificationWithMessage(message)
              }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-05-30
        • 2017-07-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多