ios - 当应用程序在后台时更新 MKMapView

标签 ios background mkmapview cllocationmanager

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

- (void)mapView:(MKMapView *)mapView
            didUpdateUserLocation:(MKUserLocation *)userLocation
{
    // The code I want to run
}

我想知道是否有可能即使应用程序在后台也能继续更新,或者如果不能,如何在 CLLocationManager 中复制这段代码。

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

最佳答案

I was wondering if it was possible to keep updating even if the app was in the background, or if not, how to replicate this code in CLLocationManager.

如果 View 未显示在屏幕上,则更新 map View 毫无意义。

如果您想在 map View 不可见时执行某些操作,您应该使用 Core Location。您需要做的就是创建一个 CLLocationManager 实例,给它一个委托(delegate),并告诉它开始更新。您的位置管理器委托(delegate)可以实现 -locationManager:didUpdateLocations: 来获取位置更新,您可以使用更新的信息做任何您想做的事情。

请注意,当应用程序处于后台时,您不应不必要地使用位置信息。在 Getting Location Updates in the Background 中阅读有关在后台获取更新的更多信息.

关于ios - 当应用程序在后台时更新 MKMapView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18450344/

相关文章:

c# - Unity Xcode LowLevelCullingLoops.cpp 崩溃

html - 为什么我的背景图片不显示?

image - 带有图像和默认渐变背景的 UINavigationBar 与 iOS5

ios - 使用自定义顺序在 MKMapview 中显示 MKAnnotationView?

swift - 如何获取 MKMapView 中隐藏了多少个注释?

ios - Storyboard问题中的 MKMapView 约束

objective-c - dateFromString 在字符串为 20130331 时出错

ios - 从 SOAP api 调用检索 json

html - Jumbotron 背景图像与 HTML 背景图像不同步

ios - 显示 YouTube 注释 - iOS 应用程序