在 ios6 中,CLLocationManager 委托方法:
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
已弃用,现在替换为:
- (void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray *)locations
为了获取最后一个位置(最新的),我们获取数组中的最后一个对象:
- (void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray *)locations{
//[locations lastObject]
}
我使用该方法来监控位置的重大变化:
- (void)applicationDidEnterBackground:(UIApplication *)application
{
if ([CLLocationManager significantLocationChangeMonitoringAvailable]) {
[locationManager startMonitoringSignificantLocationChanges];
}
}
- (void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray *)locations{
//[locations lastObject]
}
所以当应用程序进入后台时,我开始寻找设备位置的重大变化,但这通常需要一些时间来检测是否检测到位置变化,对吧?如果应用程序进入后台并且没有检测到位置变化,locationManager:didUpdateLocations:
委托方法将如何表现?