如何在每5分钟后从后台/前台获取应用程序的位置信息

我怎么才能得到它?

-(void)updateLocation { [self performSelector:@selector(updateLocation) withObject:nil afterDelay:300]; [self.locationTracker updateLocationToServer]; } 

但每次都不行

尝试使用NSTimer

 NSInteger minutes = 5; [NSTimer scheduledTimerWithTimeInterval:60 * minutes target:self selector:@selector(updateLocation) userInfo:nil repeats:YES]; 

要在后台更新位置,您需要从项目的function开启背景模式。 在这里输入图像说明

按照NA000022的build议在Capabilities中添加后台位置更新权限,并将其添加到您的位置pipe理器。

 self.locationManager.pausesLocationUpdatesAutomatically = NO; 

我也build议使用

 locationManager.distanceFilter locationManager.desiredAccuracy 

而不是更新一段时间。 由于位置更新消耗电池比任何其他服务更快。