如何找到没有信标标识符的iBeacon?

iPh*_*per 2 uuid ios ibeacon

我使用以下代码行创建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)
Run Code Online (Sandbox Code Playgroud)

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

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
}
Run Code Online (Sandbox Code Playgroud)

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

编辑:添加了CLLocationManager代码

Pau*_*w11 6

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

标识符字符串只是您分配给CLBeaconRegion应用程序中的字符串.它与实际信标中配置的任何值无关.

所以

let beaconRegion:CLBeaconRegion = CLBeaconRegion(proximityUUID: beaconUUID as UUID, identifier: "someIdentifier")
Run Code Online (Sandbox Code Playgroud)

let beaconRegion:CLBeaconRegion = CLBeaconRegion(proximityUUID: beaconUUID as UUID, identifier: "someOtherIdentifier")
Run Code Online (Sandbox Code Playgroud)

将扫描同一组iBeacons; 具有UUID指定的iBeaconsbeaconUUID

您可以使用标识符在以后识别信标区域,例如输入区域或您想要停止监视区域时.请记住,在应用程序执行过程中,信标区域保持活动状态,因此您无法依赖对象引用.