【问题标题】:CLLocationManager heading issues on iPhone 5iPhone 5 上的 CLLocationManager 标题问题
【发布时间】:2013-06-21 21:59:05
【问题描述】:

我最近开始在 iPhone 5 上测试我的应用程序,但令我震惊的是,CLLocationManager 似乎无法正常工作!虽然[CLLocationManager headingAvailable]YES,但我根本没有收到任何标题更新。奇怪的是,在 iPhone 4 上,经过 30 次左右的标题更新,locationManager:didUpdateToHeading: 不再被调用。这个问题是全新的。位置管理器还为verticalAccuracy 返回负数,所以我假设它的高度是无效的。以下是我创建位置管理器的方式:

CLLocationManager* locationManager = [[CLLocationManager alloc] init];
if([locationManager respondsToSelector:@selector(disallowDeferredLocationUpdates)]) {
   [locationManager disallowDeferredLocationUpdates];
   [locationManager setPausesLocationUpdatesAutomatically:NO];
}
locationManager.headingOrientation = CLDeviceOrientationFaceUp;
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.headingFilter = -1;
locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
[sharedSingleton setLocationManager:locationManager];

sharedSingleton 只是我的单例类,它处理一些零碎的事情,包括保持对位置管理器的引用。

如果我需要发布更多代码,请告诉我。我只是不知道是什么导致了这个奇怪的问题。谢谢!

【问题讨论】:

    标签: iphone ios cllocationmanager cllocation heading


    【解决方案1】:

    您需要在内存中的某处保留“locationManager”,作为对象的属性或实例变量。

    我相信正在发生的事情是您正在创建您的位置管理器,然后您的方法退出并且“locationManager”超出范围并被 ARC 神奇地释放。

    因此,请改为执行以下操作:

    在你的@实现中:

    @property (strong) CLLocationManager * locationManager;
    

    在你的@interface 中:

    self.locationManager = [[CLLocationManager alloc] init];
    if([self.locationManager respondsToSelector:@selector(disallowDeferredLocationUpdates)]) {
       [self.locationManager disallowDeferredLocationUpdates];
       [self.locationManager setPausesLocationUpdatesAutomatically:NO];
    }
    self.locationManager.headingOrientation = CLDeviceOrientationFaceUp;
    self.locationManager.distanceFilter = kCLDistanceFilterNone;
    self.locationManager.headingFilter = -1;
    self.locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
    

    【讨论】:

    • 我保留对位置管理器的引用,我将编辑我的问题
    • 这是单例的自动合成属性。它被声明为strongnonatomic
    【解决方案2】:

    您可以尝试一些方法。首先,我没有看到startUpdatingHeading 电话。也许你在别的地方做。您应该将locationManager:didFailWithError: 方法添加到委托以检查错误,并尝试在locationManagerShouldDisplayHeadingCalibration: 中返回YES,以防出现校准问题。

    【讨论】:

      【解决方案3】:

      似乎解决方案很明显,但我忽略了它。在位置管理器启动后不久,代理就被设置为 nil,这解释了为什么在 iPhone 4 这样较慢的设备上,在将代理设置为 nil 的代码运行之前,一些更新能够通过,但在 iPhone 上5 瞬间完成。

      【讨论】:

        猜你喜欢
        • 2015-09-03
        • 1970-01-01
        • 2013-07-01
        • 2012-11-17
        • 1970-01-01
        • 1970-01-01
        • 2019-03-13
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多