我是tvOS平台的新手。我想知道如何在应用程序启动时获取当前位置的纬度和经度。我正在编写此代码以获取位置坐标。
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
dispatch_async(dispatch_get_main_queue()) { () -> Void in
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
self.locationManager.delegate = self
self.locationManager.requestLocation()
self.locationManager.requestWhenInUseAuthorization()
}
return true
}
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
locationValue = manager.location?.coordinate
print("=========didUpdateLocations==========Latitude>>>>>",locationValue.latitude)
print("=========didUpdateLocations==========Longitude>>>>",locationValue.longitude)
}
func locationManager(manager: CLLocationManager, didFailWithError error: NSError) {
print("localizedDescription===================",error.localizedDescription)
}
此代码提供视图控制器加载后的坐标。虽然我的要求是我希望在 加载视图控制器之前获得坐标 。我可以以编程方式为单个应用程序启用位置服务吗?