How to Use CLLocationManager in multiple threads on the iPhone

Source: Internet
Author: User

DetailsIPhoneMediumMultithreadingUseCLLocationManagerIs the content to be introduced in this article.MultithreadingHow to UseCLLocationManager.

If it is a childThreadWhen CLLocationManager is created, it cannot be located after startUpdatingLocation. No proxy function is called, and MessageBox is displayed on the surface. Everything looks normal, that is, the proxy does not execute.

It seems that the returned result (calling proxy) can only be called by the main thread, and this object must be created in the main thread.

Have performed the following experiments:

1. Child thread:

 
 
  1. self.locationManager = [[CLLocationManager alloc] init] autorelease];  
  2. locationManager.delegate = self;  
  3. [locationManager startUpdatingLocation]; 

Result: No results are returned.

2. Main thread:

 
 
  1. childThread.locationManager = [CLLocationManager alloc] init];  
  2. [childThread.locationManager release];  
  3. childThreadchildThread.locationManager.delegate = childThread; 

Call in a child thread:

 
 
  1. [locationManager startUpdatingLocation]; 

Result: The proxy function is executed but called by the main thread. That is, the sub-thread starts positioning and the main thread returns results.

Summary: DetailsIPhoneMediumMultithreadingUseCLLocationManagerI hope this article will help you!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.