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

标签 ios ibeacon uuid

我正在使用下面的代码行来创建 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)

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

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 无法扫描“所有信标”。

标识符字符串只是您分配给应用程序中的 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

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

关于ios - 如何在没有信标标识符的情况下找到 iBeacon?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42822388/

相关文章:

mysql - iOS 应用程序开发 - 数据库

ios - UISegmentedControl 切换 View 它重置

ios - Swift 2 AVAudioSession setCategory 额外参数 'error'

ios - XCTest CLLocationManager 的委托(delegate)方法不会被调用

ios - iBeacon 技术将位置感知应用程序访问锁屏

java - 从没有破折号的字符串创建 UUID

ios - UIcollectionview在特定行后显示不同的单元格

ios - CoreLocation 线程崩溃崩溃 : com. apple.CoreLocation.ConnectionClient.0x16fcb870.events

ionic-framework - OneSignal 如何将 Push 发送到特定设备 - ionic

macos - 以编程方式检索 OS X 磁盘分区 UUID