Ios 当应用程序处于后台时更新MKMapView

Ios 当应用程序处于后台时更新MKMapView,ios,background,mkmapview,cllocationmanager,Ios,Background,Mkmapview,Cllocationmanager,我的iOS应用程序中有代码,在用户移动时使用MKMapView运行某些代码: - (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation { // The code I want to run } 我想知道,即使应用程序在后台,是否可以保持更新,或者如果不可以,如何在CLLocationManager中复制此代码 编辑: 我需要这个代码来获取用

我的iOS应用程序中有代码,在用户移动时使用
MKMapView
运行某些代码:

- (void)mapView:(MKMapView *)mapView
            didUpdateUserLocation:(MKUserLocation *)userLocation
{
    // The code I want to run
}
我想知道,即使应用程序在后台,是否可以保持更新,或者如果不可以,如何在
CLLocationManager
中复制此代码

编辑: 我需要这个代码来获取用户在后台的位置

我想知道,即使应用程序在后台,是否可以保持更新,或者如果不可以,如何在CLLocationManager中复制此代码

如果视图未显示在屏幕上,则更新地图视图没有意义

如果您想在地图视图不可见的情况下执行某些操作,则应使用核心位置。您需要做的就是创建
CLLocationManager
的实例,给它一个委托,并告诉它开始更新。您的location manager代理可以实现
-locationManager:didUpdateLocations:
来获取位置更新,您可以对更新的信息执行任何操作


请注意,当应用程序位于后台时,不应不必要地使用位置。阅读有关在中获取后台更新的更多信息。

您是否查看过location manager方法和回调?谢谢。这就更有意义了