我尝试找到信标,因此requestAlways总是第一次获得locationPermission,但是我更改为requestWhenInUseAuth,它找不到信标。 requestAlwaysAuth
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{
}
}
始终认证可以扫描信标吗?
答案 0 :(得分:1)
要监控信标,您必须请求并获取获取.authorizedAlways
。如果不这样做,将不会获得didEnter
或didExit
回调。您只能使用.authorizedWhenInUse
来进行 range 信标,但是显示的代码永远不会开始进行测距,而只是监视。