rkh*_*rkh 2 cllocationmanager swift ios9
我正在尝试获取设备的航向信息,以便利用磁航向和真实航向之间的差异来确定用户位置的磁偏角。为此,我有一个 Helper 类和我的 MainVc (mvc)。在我的辅助类 init 方法中,我执行以下操作:
...
...
locationManager = CLLocationManager()
switch CLLocationManager.authorizationStatus() {
case .AuthorizedAlways:
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
locationManager.startUpdatingLocation()
case .NotDetermined:
locationManager.requestAlwaysAuthorization()
case .AuthorizedWhenInUse, .Restricted, .Denied:
mvc.alertDenied();
}
if (!initialized)
{
initialized = true;
self.performSelector("finishUpdatingLocation", withObject: nil, afterDelay: 2.0);
}
}
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
print ("didUpdateLocations")
var userLocation:CLLocation = locations[0] as! CLLocation
longitude = Float(userLocation.coordinate.longitude);
latitude = Float(userLocation.coordinate.latitude);
}
func finishUpdatingLocation () {
locationManager.stopUpdatingLocation();
NSObject.cancelPreviousPerformRequestsWithTarget(self, selector: "finishUpdatingLocation", object: nil);
mvc.goingToUpdateHeading();
locationManager.startUpdatingHeading();
}
Run Code Online (Sandbox Code Playgroud)
didUpdateLocations 正在被调用,我已成功获取设备的坐标。然而,尽管我添加了 didUpdateHeading,但其中的第一行没有被打印,设备卡在此时:
func locationManager(manager: CLLocationManager, didUpdateHeading newHeading: CLHeading) {
print("didUpdateHeading");
if (newHeading.headingAccuracy > 0) {
variation = newHeading.trueHeading - newHeading.magneticHeading;
doneLoading = true;
locationManager.stopUpdatingHeading();
mvc.goingToCalculateData();
if (calcData) {
calculateData();
print ("Calculating data");
calcData = false;
}
}
print(newHeading.magneticHeading)
}
Run Code Online (Sandbox Code Playgroud)
知道为什么 startUpdatingHeading 没有被调用吗?
归档时间: |
|
查看次数: |
3713 次 |
最近记录: |