每隔5分钟如何在后台/前景中从应用中获取位置信息 [英] How can I get location from app in background/foreground after every 5 min

查看:204
本文介绍了每隔5分钟如何在后台/前景中从应用中获取位置信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取?

-(void)updateLocation {

[self performSelector:@selector(updateLocation) withObject:nil afterDelay:300];

[self.locationTracker updateLocationToServer];
}

但它并非每次都起作用。

but it's not working every time.

推荐答案

按照NA000022的建议在功能中添加后台位置更新的权限,并将其添加到您的位置管理器中。

Add the permission for background location updates in Capabilities as suggested by NA000022 and add this to your location manager.

self.locationManager.pausesLocationUpdatesAutomatically = NO;

我也建议使用

locationManager.distanceFilter 
locationManager.desiredAccuracy

持续更新时间。由于位置更新消耗的电池电量比任何其他服务都要快。

rather than updating it for time duration. Since location updates consume battery faster than any other services.

这篇关于每隔5分钟如何在后台/前景中从应用中获取位置信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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