didUpdateLocations instead of didUpdateToLocation

YogevSitton picture YogevSitton · Sep 26, 2012 · Viewed 39.2k times · Source

With the release of iOS6 Apple wants us to use didUpdateLocations instead of didUpdateToLocation. Can anyone explain how to properly use didUpdateLocations?

Answer

Anne picture Anne · Sep 26, 2012

I asume you used the following delegate to get the last position?

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

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]

In other words, [locations lastObject] (new delegate) equals newLocation (old delegate) .