在 iOS 5 中,委托方法是
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
其中,如在iOS 6方法中是
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
我的应用程序支持这两个版本。CLLocation 管理将知道它应该调用哪个方法?我需要添加一些 #if 定义吗?如果是,谁能告诉我我该怎么写这个。提前谢谢。
- (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创建一个数组,并传递给这个。但我认为不需要这样做。您可以在两个设备中进行测试。