ios - 如何在后台快速跟踪用户位置
问题描述
我正在尝试在后台跟踪用户位置,我尝试在使用时使用和不使用时,但每次我最小化应用程序时,位置图标都会消失,我在教程中阅读过它应该显示蓝条,但我没有得到那个酒吧我还检查了更新位置的后台模式
map.showsUserLocation = true
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestWhenInUseAuthorization()
locationManager.requestAlwaysAuthorization()
locationManager.startUpdatingLocation()
// Do any additional setup after loading the view, typically from a nib.
alwaysAuthorization()
}
func alwaysAuthorization(){
if CLLocationManager.locationServicesEnabled() && CLLocationManager.authorizationStatus() == .authorizedWhenInUse {
locationManager.requestAlwaysAuthorization()
}
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let location = locations.last
let region = MKCoordinateRegion(center: CLLocationCoordinate2D(latitude: location!.coordinate.latitude, longitude: location!.coordinate.longitude), span: MKCoordinateSpan (latitudeDelta: 0.2, longitudeDelta: 0.2))
self.map.region = region
print("location \(location!.coordinate.latitude) and \(location!.coordinate.longitude)")
}
解决方案
这就是我要找的
locationManager.allowsBackgroundLocationUpdates = true
推荐阅读
- sitecore - 在体验编辑器中向新页面添加新组件时,sitecore 9.3 中未添加
- javascript - 重新初始化 select2 数据
- kubernetes - pv 中kubernetes accessModes 的用途 PVC
- r - 字符串未被识别为在 r 中用 stringr 替换
- javascript - 如何编辑发票 Qweb 报告的默认标题。奥多 14
- javascript - javascript出错后如何重置Google OAuth2?
- html - 输入类型数值在角度反应形式中出错
- ruby-on-rails - 用户通过 elasticsearch 创建复杂的查询和搜索
- opengl - 当我将几何着色器添加到着色程序而不是对象不渲染时
- php - PHP文件写入格式