我尝试找到信标,所以总是第一次请求获取 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
。如果你不这样做,你将不会得到 didEnter
或 didExit
回调。您可以仅使用 .authorizedWhenInUse
range 信标,但显示的代码永远不会开始测距,仅进行监控。
关于swift - iBeacon swift 在检测 Beacon 时需要 'requestWhenInUseAuth'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54102822/