【发布时间】:2020-04-20 16:51:01
【问题描述】:
当应用程序在前台工作时我可以扫描信标,但不能在后台工作应用程序。我在 İinfo.plist 和后台模式“位置更新”中添加了“隐私 - 始终位置和使用时的使用说明”和“隐私 - 使用时的位置使用说明”
func initScanBeacon() {
locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.requestAlwaysAuthorization()
locationManager.allowsBackgroundLocationUpdates = true
locationManager.pausesLocationUpdatesAutomatically = false
}
func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
if status == .authorizedAlways {
if CLLocationManager.isMonitoringAvailable(for: CLBeaconRegion.self) {
if CLLocationManager.isRangingAvailable() {
startScanning()
}
}
}
}
func startScanning() {
let uuid = UUID(uuidString: "xxxxx")!
let beaconRegion = CLBeaconRegion(proximityUUID: uuid, major: 0, minor: 0, identifier: "xxxxx")
locationManager.startMonitoring(for: beaconRegion)
locationManager.startRangingBeacons(in: beaconRegion)
}
func locationManager(_ manager: CLLocationManager, didRangeBeacons beacons: [CLBeacon], in region: CLBeaconRegion) {
if beacons.count > 0 {
//print
} else {
}
}
【问题讨论】:
标签: swift core-location beacon