gpt4 book ai didi

objective-c - 实现弃用的方法 - CLLocation

转载 作者:搜寻专家 更新时间:2023-10-30 19:40:59 24 4
gpt4 key购买 nike

对于 Xcode 9.3,我有一个新的警告。

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

此方法现已弃用。“实现弃用的方法”。我有你的解决方案吗?谢谢

最佳答案

Apple Documentation on locationManager(_:didUpdateTo:from:)会告诉你使用 locationManager(_:didUpdateLocations:)


因此对于新委托(delegate) locationManager(_:didUpdateLocations:)locations 对象的文档说明:

locations

An array of CLLocation objects containing the location data. This array always contains at least one object representing the current location. If updates were deferred or if multiple locations arrived before they could be delivered, the array may contain additional entries. The objects in the array are organized in the order in which they occurred. Therefore, the most recent location update is at the end of the array.

基本上这意味着数组中至少有 1 个位置,如果超过 1 个,则:

  1. locations 数组中的最后一个对象将是新/当前位置
  2. locations 数组中的倒数第二个对象将是旧位置

示例(Swift 4+):

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let newLocation = locations.last

let oldLocation: CLLocation?
if locations.count > 1 {
oldLocation = locations[locations.count - 2]
}
//...
}

示例( Objective-C ):

-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations {
CLLocation *newLocation = locations.lastObject;

CLLocation *oldLocation;
if (locations.count > 1) {
oldLocation = locations[locations.count - 2];
}
//...
}

引用:

关于objective-c - 实现弃用的方法 - CLLocation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49688428/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com