重要的位置变化至少每15分钟不会触发 [英] significant location change does not trigger at least every 15min

查看:164
本文介绍了重要的位置变化至少每15分钟不会触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据苹果文档,重要的位置变化应该至少每15分钟更新一次位置。我确实在移动时收到更新,但在设备静止时却没有。您对更新的体验是什么?他们至少每15分钟来一次吗?

According to apple docs, significant location change should update location at least every 15min. I am indeed receiving updates when I move significantly, but not when the device is stationary. What is your experience with updates? Do they come at least every 15min?


如果GPS级准确度对你的应用并不重要而且你不需要
连续跟踪,您可以使用重要更改位置
服务。正确使用重要更改位置
服务至关重要,因为它会每15分钟唤醒系统和您的应用至少
,即使没有发生位置更改,并且
运行一直持续到你停止它。

If GPS-level accuracy isn’t critical for your app and you don’t need continuous tracking, you can use the significant-change location service. It’s crucial that you use the significant-change location service correctly, because it wakes the system and your app at least every 15 minutes, even if no location changes have occurred, and it runs continuously until you stop it.


推荐答案

好吧,我有一个天真的解决方案。您可以使用NSTimer强制CLLocationManger实例每15分钟更新一次当前位置,或者您希望定期更新的时间。

Well, I have a naive solution. You can use a NSTimer to force the CLLocationManger instance to update the current location every 15 minutes or whatever the time you want it to be periodically updated.

这是我想要的代码使用:

Here's the code I would use:

首先,请在viewDidLoad或其他地方调用此方法开始更新您的位置。

First, call this method to start update your location whenever you need in your viewDidLoad or else where.

- (void)startStandardUpdates
{
    if (nil == locationManager){
        locationManager = [[CLLocationManager alloc] init];
    }

    locationManager.delegate = self;
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;

    // 900 seconds is equal to 15 minutes
    NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:900 target:self selector:@selector(updateUserLocation) userInfo:nil repeats:YES];
    [timer fire];    
}

其次,实现updateUserLocation方法:

Second, implement the updateUserLocation method:

-(void)updateUserLocation{
    [self.locationManager startUpdatingLocation];
}

最后,确认协议,然后执行location did update方法。我们阅读了最新的更新结果,并让位置经理停止更新当前位置,直到下一个15分钟。:

Last, confirm to the protocol, then implement the location did update method. We read the latest updated result and let the location manager to stop updating current location until next 15 minutes.:

-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations{
    CLLocation *userLocation = [locations objectAtIndex:0];
    CLLocationCoordinate2D userLocationCoordinate = userLocation.coordinate;
    /*
    Do whatever you want to update by using the updated userLocationCoordinate.
    */
    [manager stopUpdatingLocation];
}

这篇关于重要的位置变化至少每15分钟不会触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆