【发布时间】:2017-03-15 23:06:40
【问题描述】:
我正在使用以下代码行创建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 是标识符字符串。问题是因为我的应用程序将检测到通用 iBeacons,所以我可能不知道他们的 beaconIdentifier 字符串(这不是 UUID,只是一个标识符)。有什么方法可以将它作为通用字符串或 nil 传递(以消除依赖性)?
编辑:添加 CLLocationManager 代码
【问题讨论】: