详解iPhone中在多线程停使用CLLocationManager

详解iPhone中在多线程下使用CLLocationManager
详解iPhone中在多线程下使用CLLocationManager是本文要介绍的内容,主要是介绍在多线程下如何使用CLLocationManager,一起来看本文详细内容讲解。

如果是子线程中创建CLLocationManager,那么startUpdatingLocation后是无法定位的,任何代理函数都不会被调用,而且表面上还会有提示是否定位的MessageBox,一切看起来都正常,就是代理不会执行。

似乎定位的返回(调用代理)只能有主线程来调用,并且这个对象还必须是在主线程创建的。

做过以下实验:

1.子线程中:

self.locationManager = [[CLLocationManager alloc] init] autorelease]; 
locationManager.delegate = self; 
[locationManager startUpdatingLocation];
结果:不会有任何结果返回。

2.主线程中:

childThread.locationManager = [CLLocationManager alloc] init]; 
[childThread.locationManager release]; 
childThreadchildThread.locationManager.delegate = childThread;
在子线程中调用:

[locationManager startUpdatingLocation];
结果:代理函数会执行,但是是由主线程来调用的。也就是子线程启动定位,主线程返回结果。

小结:详解iPhone中在多线程下使用CLLocationManager的内容介绍完了,希望本文对你有所帮助!
原文地址:http://www.61ic.com/Mobile/iPhone/201108/36698.html