简体   繁体   中英

Can we create CLLocation updates on background thread?

Hi in my iOS app I should fetch CLLocation updates in a background thread hence I have created CLLocation object like follows

  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 ();

    });

Is it okay? I read it on some portal, as per apple guidelines we should call CLLocation updates strictly on Main thread, Is that so?

It is not necessary to call the locationManager from a background thread, most of its call are asynchronous. So it is best to call it from the main thread though not required. Also, it is important to note that whatever thread you start the 'locationmanager' from is the thread its delegates will be called on.

As per the docs:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM