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:
- self.locationManager = [[CLLocationManager alloc] init] autorelease];
- locationManager.delegate = self;
- [locationManager startUpdatingLocation];
Result: No results are returned.
2. Main thread:
- childThread.locationManager = [CLLocationManager alloc] init];
- [childThread.locationManager release];
- childThreadchildThread.locationManager.delegate = childThread;
Call in a child thread:
- [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!