我可以让位置管理员在后台正确更新位置,但只有在手机连接到我的macbook时才能更新]:
在pList中,我有 NSLocationAlwaysUsageDescription 值以及 应用程序寄存器进行位置更新所需的背景模式 和 应用程序从网络下载内容
在AppDelegate中我懒得加载locationManager,然后在viewcontroller初始化之后,我调用 locationManager.startUpdatingLocation()
lazy var locationManager:CLLocationManager! = {
let manager = CLLocationManager()
manager.desiredAccuracy = kCLLocationAccuracyBest
manager.delegate = self
manager.allowsBackgroundLocationUpdates = true
manager.requestAlwaysAuthorization()
return manager
}()
func locationManager(manager: CLLocationManager!, didUpdateToLocation newLocation: CLLocation!, fromLocation oldLocation: CLLocation!) {
// Add another annotation to the map.
let annotation = MKPointAnnotation()
annotation.coordinate = newLocation.coordinate
var latitude:String = annotation.coordinate.latitude.description
var longitude:String = annotation.coordinate.longitude.description
print("new location...\(latitude) - \(longitude)")
}
我做错了什么?