如何在没有信标标识符的情况下找到 iBeacon?

How to find iBeacon without beacon identifier?

我正在使用以下代码行创建 CLBeaconRegion,然后按以下方式调用 location manager

 let beaconRegion:CLBeaconRegion = CLBeaconRegion(proximityUUID: beaconUUID as UUID,
                                                                 identifier: beaconIdentifier)

///  save a beacon region for stopping after.
                (beaconInfo as! BeaconInfo).beaconRegion = beaconRegion

                ///  start monitoring the specified region.
                self.locationManager.startMonitoring(for: beaconRegion)

                ///  start calculating ranges for beacons in the specified region.
                self.locationManager.startRangingBeacons(in: beaconRegion)

位置管理器委托中的代码是:

func locationManager(_ manager: CLLocationManager,
                         didRangeBeacons beacons: [CLBeacon],
                         in region: CLBeaconRegion) {

        ///  it may be assumed no beacons that match the specified region are nearby.
        if beacons.count == 0 {
            print ("beacon.count = 0")
            return
        }
else
{
     \executed rest of the code
}

其中 beaconUUID 是我的 iBeacon 的 UUID,beaconIdentifier 是标识符字符串。问题是因为我的应用程序将检测通用 iBeacon,所以我可能不知道它们的 beaconIdentifier 字符串(不是 UUID,只是一个标识符)。有什么方法可以将其作为通用字符串或 nil 传递(以消除依赖性)?

编辑:添加了 CLLocationManager 代码

不,您需要知道您正在寻找的信标的 UUID。 iOS 无法扫描 "all beacons".

标识符字符串只是您在应用程序中分配给 CLBeaconRegion 的字符串。它与实际信标中配置的任何值都没有关系。

所以

let beaconRegion:CLBeaconRegion = CLBeaconRegion(proximityUUID: beaconUUID as UUID, identifier: "someIdentifier")

let beaconRegion:CLBeaconRegion = CLBeaconRegion(proximityUUID: beaconUUID as UUID, identifier: "someOtherIdentifier")

都将扫描同一组 iBeacon;具有 beaconUUID

指定的 UUID 的 iBeacon

您可以在以后使用该标识符来识别信标区域,例如当进入该区域或您想停止监视某个区域时。请记住,信标区域在您的应用程序执行期间保持活动状态,因此您不能依赖对象引用。

所以问题是每个信标都需要有唯一的标识符字符串。这就是为什么我的应用程序没有检测到的原因,因为我有一个用于所有信标的通用字符串。