如果两个iBeacon靠近在一起,一个信号可以在去往设备(iPhone)的路上覆盖另一个

问题描述 投票:0回答:2

我有一个简单的问题,我无法找到答案。我正在测试一个带有一些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 DSDTECHlocationE 33803

UPDATE

我更改了major/minor值(与另一个信标相冲突......但不是因为UUID不同......所以它不应该重要)现在灯塔在didDetermineState期间被识别...但我没有收到测距过程中的任何信息。我可以在日志中看到它通过locationManager?.startRangingBeacons(in: region as! CLBeaconRegion)函数`...所以我应该从它接收信息(UUID / major / minor / identifier / anything)。

ios iphone swift ibeacon detection
2个回答
0
投票

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

我想你错过了status。当任何区域的状态发生变化(确实退出,或确实进入)或者您明确地为该区域调用didDetermineState时,都会调用requestStateForRegion。日志中有一个信标的两个状态,我认为一个是状态输入,另一个是状态退出。

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)

0
投票

在搞清楚了didDetermineState之后,我拿起了我的iBeacon并将其插入离我更近的地方,它开始接收信息 - 所以它只是一个糟糕的灯塔:)

© www.soinside.com 2019 - 2024. All rights reserved.