iOS重大位置更改更新(位置更新频率)

时间:2015-03-11 06:10:15

标签: ios ios8 cllocationmanager

在我的应用程序中,我需要能够在用户位置发生重大变化时从终止状态打开应用程序,因此我调用CLLocationManager的startMonitoringSignificantLocationChanges方法就是这样做的。

该应用程序正在打开,但问题是我在很长一段时间后获得位置更改更新,例如20分钟,即使我已经移动了1000米有时我根本没有得到任何更新。我需要在500米后更新。如果等待很长一段时间对我来说并不重要,但我需要在500米之后更新,根据Apple的文档here,这被认为是重要的位置变更。

- (void) checkIfSignificantLocationChange : (NSDictionary *) launchOptions {

    // Application is launched because of a significant location change
    if ([launchOptions objectForKey:UIApplicationLaunchOptionsLocationKey])
    {
        bgTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
            [[UIApplication sharedApplication] endBackgroundTask:bgTask];
        }];
        CLLocationManager *locationManager = [CLLocationManager new];
        CLLocation *location = [locationManager location];
        [locationManager startMonitoringSignificantLocationChanges];

        if (bgTask != UIBackgroundTaskInvalid)
        {
            //Clean up code. Tell the system that we are done.
            [[UIApplication sharedApplication] endBackgroundTask: bgTask];
            bgTask = UIBackgroundTaskInvalid;
        }
    }
}

有人可以帮助我看看我在这里做错了什么吗?为什么我有时在30分钟以后没有得到任何更新,即使我已经移动了超过500米。

当应用检测到重要的位置更改时,系统会调用此方法。我使用iOS模拟器位置 - 高速公路驱动器进行测试,因为我厌倦了到处驾车。

提前致谢!!

0 个答案:

没有答案
相关问题