didUpdateLocations而不是didUpdateToLocation [英] didUpdateLocations instead of didUpdateToLocation
问题描述
随着iOS6的发布,Apple希望我们使用didUpdateLocations而不是didUpdateToLocation。任何人都可以解释如何正确使用didUpdateLocations吗?
With the release of iOS6 Apple wants us to use didUpdateLocations instead of didUpdateToLocation. Can anyone explain how to properly use didUpdateLocations?
推荐答案
我认为您使用以下代理来获取最后一个位置?
I asume you used the following delegate to get the last position?
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
上面的代理在iOS 6中已弃用。现在应该使用以下代码:
The delegate above is deprecated in iOS 6. Now the following should be used:
- (void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray *)locations
为了得到最后一个位置,只需获取数组的最后一个对象:
In order to get the last position, simply get the last object of the array:
[locations lastObject]
在其他单词, [locations lastObject]
(新委托)等于 newLocation
(旧委托)。
In other words, [locations lastObject]
(new delegate) equals newLocation
(old delegate) .
这篇关于didUpdateLocations而不是didUpdateToLocation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!