ios - 我们可以在后台线程上创建 CLLocation 更新吗?

标签 ios iphone multithreading cllocationmanager cllocation

嗨,在我的 iOS 应用程序中,我应该在后台线程中获取 CLLocation 更新,因此我创建了 CLLocation 对象,如下所示

  dispatch_queue_t globalConcurrentQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0);
    dispatch_async(globalConcurrentQueue,^{

 objAppDelegate.locationManager.DistanceFilter =Constants.kDISTANCE_FILTER;
                            objAppDelegate.locationManager.DesiredAccuracy =CLLocation.AccurracyBestForNavigation;
                            objAppDelegate.locationManager.StartUpdatingLocation ();

    });

还好吗?我在一些门户网站上读到它,根据苹果指南,我们应该严格在主线程上调用 CLLocation 更新,是这样吗?

最佳答案

没有必要从后台线程调用locationManager,它的大部分调用都是异步的。所以最好从主线程调用它,尽管不是必需的。此外,重要的是要注意,无论您从哪个线程启动“locationmanager”,都会调用其委托(delegate)的线程。

根据文档:

The methods of your delegate object are called from the thread in which you started the corresponding location services. That thread must itself have an active run loop, like the one found in your application’s main thread.

关于ios - 我们可以在后台线程上创建 CLLocation 更新吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32825138/

相关文章:

ios - 如何将字符串转换为 CLLocationDegrees Swift 2

ios - 如何使用后退按钮使导航栏透明,并且 webView 将显示到状态栏的边缘

ios - Apple WebKit 已弃用?

iphone - 构建复杂的 iPhone 应用程序?

php - 从 iPhone 发布图像时出现奇怪问题

iphone - UISearchBar inputAccessoryView 的问题

iphone - 使用标签以编程方式创建后在 iOS 中移动多个图像

java - 线程安全迭代解释

java - 多线程旧版Java应用程序的线程按顺序轮流

ios - DispatchQueue.concurrentPerform 内存损坏