2012-11-27 41 views
0

在iOS 5中CLLocationManager調用正確的委託方法,委託方法如何可以根據IOS版本

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation 

,其中在iOS 6中的方法是

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations 

我的應用程序支持的版本。 CLLocation管理如何知道應該調用哪種方法? 我需要添加一些#if def嗎?如果是的話,有人可以告訴我怎麼寫這個。 在此先感謝。

回答

1

您可以使用

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation;

您可使用iOS 6的SDK,並設置部署目標,以支持iOS 5的爲好。如果它不起作用,你可以嘗試實現這個方法,並在裏面調用- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations (你也可以實現這個iOS 6方法,以便在iOS 6的情況下直接調用這個方法)。你可以用newLocation和oldLocation創建一個數組並傳給它。但我不認爲這將是必要的。您可以在兩個設備中進行測試。

相關問題