【问题标题】:CLLocationManager Delegate method didUpdateToLocation not called on user's deviceCLLocationManager 委托方法 didUpdateToLocation 未在用户设备上调用
【发布时间】:2014-09-04 18:49:34
【问题描述】:

我的应用需要位置数据才能运行。我确保用户在登录之前必须接受我的应用的位置服务。如果用户拒绝,它将阻止用户登录,直到用户授予应用使用位置服务的权限。

除了 1 个测试用户的设备外,一切都运行良好。即使用户授予应用位置服务权限,设备也根本没有获取位置数据。没有出现 GPS 图标。谷歌地图在用户的设备上运行良好。我真的不确定这里发生了什么。看起来didUpdateToLocation 根本没有在此用户的设备上调用。什么可能导致此问题?

代码:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    ...
    [self getCurrentLocation];
    ...
}

- (void)getCurrentLocation {
    if (nil == locationManager)
        locationManager = [[CLLocationManager alloc] init];
    locationManager.delegate = self;
    locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;
    locationManager.distanceFilter = 100; // meters
    [locationManager startMonitoringSignificantLocationChanges];
}

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    CLLocation *currentLocation = newLocation;
    if (currentLocation != nil) {
        [self setLatitude:[NSNumber numberWithFloat:currentLocation.coordinate.latitude]];
        [self setLongitude:[NSNumber numberWithFloat:currentLocation.coordinate.longitude]];
        if (loginController) {
            [loginController validateSession];
            loginController = nil;
        }

    }
}

【问题讨论】:

  • 如果您在设备中尝试,请删除 locationManager.distanceFilter = 100;因为在您的手机每步行 100 米后调用 didupdate location 方法进行测试,您可以将其移除

标签: ios iphone gps location cllocationmanager


【解决方案1】:

请检查以下推荐。有时我也会遇到同样的问题。

  1. 完全卸载并重新安装并再次检查应用程序。

  2. 在 iPhone 设置中重置网络设置。

  3. 删除之前安装的应用程序并重新安装。

【讨论】:

    【解决方案2】:

    你没有使用

    - (void)startUpdatingLocation;
    

    但你使用

    - (void)startMonitoringSignificantLocationChanges;
    

    由于您设置了所有过滤器,您可能希望使用第一个 (startUpdatingLocation)。

    至于为什么这对单个用户的设备不起作用:startMonitoringSignificantLocationChanges 不使用 GPS 来三角定位用户的位置,因此将其与谷歌地图进行比较对您没有帮助。

    有关这两种方法的更多信息,请在 Apple 的文档中进一步调查: Apple Doku

    【讨论】:

    • 这不是真的。它适用于所有其他用户。 GPS 图标出现在除此用户之外的所有其他设备上。 startMonitoringSignificantLocationChanges 只是更新频率较低,位置事件的传递比 startUpdatingLocation 慢
    • 这些行:locationManager.desiredAccuracy = kCLLocationAccuracyKilometer; locationManager.distanceFilter = 100; // 如果您使用 startMonitoringSignificantLocationChanges,则完全忽略仪表。这就是我想指出的。实际上是的,startMonitoringForSig.. 不需要 GPS,但它有时会使用它。但反之则需要 wifi 或蜂窝网络!
    猜你喜欢
    • 1970-01-01
    • 2015-10-01
    • 2016-05-12
    • 2011-11-29
    • 1970-01-01
    • 2013-12-03
    • 2011-03-12
    • 2016-05-07
    • 2011-11-18
    相关资源
    最近更新 更多