ios - 如果两个 iBeacon 靠得很近,一个信号能否在传输到设备 (iPhone) 时覆盖另一个信号

标签 ios iphone swift ibeacon detection

我有一个简单的问题,但找不到答案。我正在使用一些 iBeacons 测试一个应用程序,我发现我的一个 iBeacons 从未开始测距……该区域受到监控,只是没有被检测到。当我查看控制台输出时,会检测到其他信标,然后几秒钟后,会检测到另一个信标,但它具有与已检测到的其他位置之一相同的 UUID/主要/次要/标识符值。

因此,除了一个信标之外,所有信标都会被识别,并且它们的状态也会被确定。然后,似乎已经确定的信标之一再次被确定(相同的信息)。这些信标有点靠近(x、y 方向相距约一米,但位于不同楼层(二楼和三楼),我想知道一个信标信号是否可以覆盖另一个信标信号......这就是为什么我看到其中一个信标的信息两次。否则我不确定为什么我无法检测到这个信标。

这是我的一些代码,我对其进行了梳理,我找不到任何人为错误的问题,例如输入正确的主要/次要/UUID 值。

调用此函数以开始监视信标:

    func monitorBeacons() {
        print("monitorBeacons()")
        if CLLocationManager.isMonitoringAvailable(for:
            CLBeaconRegion.self) {
            print("monitorBeacons().monitoringIsAvailable")
            // Match all beacons with the specified UUID
            let proximityUUIDA = UUID(uuidString:
                "12345678-B644-4520-8F0C-720EAF059935")
            let proximityUUIDB = UUID(uuidString:
                "E2C56DB5-DFFB-48D2-B060-D0F5A71096E0")

            let beaconRegionA = CLBeaconRegion(
                proximityUUID: proximityUUIDB!,
                major: 0x0001,
                minor: 0x0004,
                identifier: "locationA 49398")

            let beaconRegionB = CLBeaconRegion(
                proximityUUID: proximityUUIDB!,
                major: 0x0001,
                minor: 0x0002,
                identifier: "locationB 49267")

            let beaconRegionC = CLBeaconRegion(
                proximityUUID: proximityUUIDB!,
                major: 0x0001,
                minor: 0x0005,
                identifier: "locationC 49141")

            let beaconRegionD = CLBeaconRegion(
                proximityUUID: proximityUUIDA!,
                major: 0x0001,
                minor: 0x0002,
                identifier: "locationD DSDTECH")

            let beaconRegionE = CLBeaconRegion(
                proximityUUID: proximityUUIDB!,
                major: 0x0001,
                minor: 0x0001,
                identifier: "locationE 33803")

            self.locationManager?.startMonitoring(for: beaconRegionA)
            self.locationManager?.startMonitoring(for: beaconRegionB)
            self.locationManager?.startMonitoring(for: beaconRegionC)
            self.locationManager?.startMonitoring(for: beaconRegionD)
            self.locationManager?.startMonitoring(for: beaconRegionE)

            print("\(String(describing: self.locationManager?.monitoredRegions)) + monitoredRegions")
        }
    }

当它们的状态被确定时,就会发生这种情况:

    func locationManager(_ manager: CLLocationManager, didDetermineState state: CLRegionState, for region: CLRegion) {
        if region is CLBeaconRegion {
            print("determined state of beacon for region - \(region)")
            // Start ranging only if the feature is available.
            if CLLocationManager.isRangingAvailable() {
                print("determined state of beacon and started ranging")
                locationManager?.startRangingBeacons(in: region as! CLBeaconRegion)
                // Store the beacon so that ranging can be stopped on demand.
                beaconsToRange.append(region as! CLBeaconRegion)
            }
        }
    }

控制台输出:

determined state of beacon for region - CLBeaconRegion (identifier:'locationA 49398', uuid:E2C56DB5-DFFB-48D2-B060-D0F5A71096E0, major:1, minor:4)
determined state of beacon for region - CLBeaconRegion (identifier:'locationB 49267', uuid:E2C56DB5-DFFB-48D2-B060-D0F5A71096E0, major:1, minor:2)
determined state of beacon for region - CLBeaconRegion (identifier:'locationC 49141', uuid:E2C56DB5-DFFB-48D2-B060-D0F5A71096E0, major:1, minor:5)
determined state of beacon for region - CLBeaconRegion (identifier:'locationE 33803', uuid:E2C56DB5-DFFB-48D2-B060-D0F5A71096E0, major:1, minor:1)
determined state of beacon for region - CLBeaconRegion (identifier:'locationE 33803', uuid:E2C56DB5-DFFB-48D2-B060-D0F5A71096E0, major:1, minor:1)

您可以看到最后两个信标是相同的,但它不应该为一个信标确定两次状态,这就是为什么我认为信号可能对于我丢失的那个信标感到困惑locationD DSDTECH locationE 33803

更新

我更改了主要/次要值(这与另一个信标冲突......但并不是真的,因为UUID不同......所以它应该' t 很重要),现在信标在 didDetermineState 期间被识别...但在测距期间我没有收到任何信息。我可以在日志中看到它经历了 locationManager?.startRangingBeacons(in: Region as! CLBeaconRegion) 函数`...所以我应该接收信息(UUID/major/minor/identifier/任何东西)从中。

最佳答案

具有相同 UUID、主要和次要的多个信标将表现得像一个区域。

我认为您缺少状态。当任何区域的状态发生变化(退出或进入)时,或者您为该区域显式调用 requestStateForRegion 时,都会调用 didDetermineState 。日志中一个信标的两种状态,我认为一种用于状态进入,另一种用于状态退出。

didDetermineState中检查区域状态,并且仅当区域状态为CLRegionStateInside时才开始狂暴

if state == CLRegionStateInside {
    locationManager?.startRangingBeacons(in: region as! CLBeaconRegion)
    beaconsToRange.append(region as! CLBeaconRegion)
}

如果您已经在该区域中,则不会调用 didDetermineState ,除非您退出该区域并再次进入。为了克服这个问题,您应该像这样为每个区域调用 requestStateForRegion

self.locationManager?.startMonitoring(for: beaconRegionA)
self.locationManager?.requestState(for: beaconRegionA)

关于ios - 如果两个 iBeacon 靠得很近,一个信号能否在传输到设备 (iPhone) 时覆盖另一个信号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49073422/

相关文章:

ios - 在没有用户交互的情况下恢复 iOS 8 上的应用内购买?

ios - 在 iOS 中当设备语言为阿拉伯语时显示英文键盘和类型

iphone - 核心数据获取不一致

iOS : How to get song id using echonest Api

ios - Facebook FBSDK Corekit 的语义问题

swift - UICollectionView 中的自定义单元格

ios - 更新数据与更新 UI 的困境

ios - 第二次单击文本字段时键盘未显示 View

iphone - 将 managedObjectContext(核心数据)传递给其他类,正确完成了吗?

iphone - Objective-C 中的二维数组?