iBeacon swift 在检测 Beacon 时需要 'requestWhenInUseAuth'?
iBeacon swift needs 'requestWhenInUseAuth' when detect Beacon?
我尝试找到beacon,所以requestAlways第一次获取locationPermission,但是我改成requestWhenInUseAuth,找不到beacon。
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{
}
}
alwaysAuth应该可以扫描beacon吗?
为了监控 信标,您必须请求并获得 .authorizedAlways
。如果您不这样做,您将不会收到 didEnter
或 didExit
回调。您可以 范围 信标仅 .authorizedWhenInUse
,但显示的代码从未开始测距,仅监控。
我尝试找到beacon,所以requestAlways第一次获取locationPermission,但是我改成requestWhenInUseAuth,找不到beacon。 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{
}
}
alwaysAuth应该可以扫描beacon吗?
为了监控 信标,您必须请求并获得 .authorizedAlways
。如果您不这样做,您将不会收到 didEnter
或 didExit
回调。您可以 范围 信标仅 .authorizedWhenInUse
,但显示的代码从未开始测距,仅监控。