我在视图出现时开始更新当前位置,并在每次locationManager:didUpdateLocations:调用时停止更新位置.但为什么locationManager:didUpdateLocations:总是多次被召唤?我错过了什么?
#import "ViewController.h"
@interface ViewController (){
CLLocationManager *locationManager; // location manager for current location
}
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self startUpdatingCurrentLocation];
}
- (void)startUpdatingCurrentLocation
{
if (!locationManager)
{
locationManager = [[CLLocationManager alloc] init];
[locationManager setDelegate:self];
locationManager.distanceFilter = 10.0f; // we don't need to be any more accurate than 10m
}
[locationManager startUpdatingLocation];
}
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{
[locationManager stopUpdatingLocation];
}
@end
Run Code Online (Sandbox Code Playgroud) 我正在研究地图应用,
我尝试使用[locationManager stopUpdatingLocation];方法来停止Location服务.
它似乎在iOS4.3中运行良好,但在iOS5中,它无法正常工作.
请任何人建议我如何在iOS5中停止位置服务?