嗨,在我的 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/