詳解iPhone中在多線程下使用CLLocationManager
詳解iPhone中在多線程下使用CLLocationManager是本文要介紹的內(nèi)容,主要是介紹在多線程下如何使用CLLocationManager,一起來看本文詳細內(nèi)容講解。
如果是子線程中創(chuàng)建CLLocationManager,那么startUpdatingLocation后是無法定位的,任何代理函數(shù)都不會被調(diào)用,而且表面上還會有提示是否定位的MessageBox,一切看起來都正常,就是代理不會執(zhí)行。
似乎定位的返回(調(diào)用代理)只能有主線程來調(diào)用,并且這個對象還必須是在主線程創(chuàng)建的。
做過以下實驗:
1.子線程中:
- self.locationManager = [[CLLocationManager alloc] init] autorelease];
- locationManager.delegate = self;
- [locationManager startUpdatingLocation];
結(jié)果:不會有任何結(jié)果返回。
2.主線程中:
- childThread.locationManager = [CLLocationManager alloc] init];
- [childThread.locationManager release];
- childThreadchildThread.locationManager.delegate = childThread;
在子線程中調(diào)用:
- [locationManager startUpdatingLocation];
結(jié)果:代理函數(shù)會執(zhí)行,但是是由主線程來調(diào)用的。也就是子線程啟動定位,主線程返回結(jié)果。
小結(jié):詳解iPhone中在多線程下使用CLLocationManager的內(nèi)容介紹完了,希望本文對你有所幫助!