swift - iBeacon swift 在检测 Beacon 时需要 'requestWhenInUseAuth'?

标签 swift permissions ibeacon

我尝试找到信标,所以总是第一次请求获取 locationPermission,但我更改为 requestWhenInUseAuth,它找不到信标。 请求始终验证

locationManager = CLLocationManager.init()
        locationManager.delegate = self
        locationManager.requestWhenInUseAuthorization()

func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {

        if status == .authorizedWhenInUse {
            monitorBeacons()
        }

    }

func locationManager(_ manager: CLLocationManager, didRangeBeacons beacons: [CLBeacon], in region: CLBeaconRegion) {

        if beacons.count > 0 {

            majorArray.removeAll()

            for beacon in beacons {
                //                print("uuid: \(beacon.proximityUUID.uuidString) major: \(beacon.major) minor: \(beacon.minor)")

                let major = "\(beacon.major)"
                let num = (major as NSString).integerValue

                if !majorArray.contains(num){
                    majorArray.append(num)

                }

            }

        }else{



        }

    }

alwaysAuth应该可以扫描beacon吗?

最佳答案

为了监控信标,您必须请求并获得 .authorizedAlways。如果你不这样做,你将不会得到 didEnterdidExit 回调。您可以仅使用 .authorizedWhenInUserange 信标,但显示的代码永远不会开始测距,仅进行监控。

关于swift - iBeacon swift 在检测 Beacon 时需要 'requestWhenInUseAuth'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54102822/

相关文章:

android - Android 和 iOS 中 ble 扫描率的差异

ios - 如何在 map 中显示 iBeacon

swift - 核心数据显示获取数据问题

ios - 在 ios 10.2.1 中打电话时不显示确认对话框,但在 10.3 中显示

linux - Bare Git repo 无法添加文件或提交文件

linux - 为Linux目录下新创建的文件和子目录设置默认权限?

swift - 向 UIBarButtonItem Swift 添加操作

ios - 当 TableViewCell 超出 View 时改变它的大小

python - OpenSSH 公钥不适用于 Cygwin

android - BluetoothLeAdvertiser 是否适用于装有 Android 5.0 的 Nexus 5?