【发布时间】:2014-04-15 16:34:21
【问题描述】:
我的目标是每当应用程序进入前台时,我都会获取位置以更新我的天气预报。我要做的是
- (void)viewDidLoad
{
[super viewDidLoad];
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move
self.locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; // 100 m
}
- (void)viewWillAppear:(BOOL)animated
{
self.locationManager.delegate = self;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(enterForeground) name:UIApplicationWillEnterForegroundNotification object:nil];
}
#pragma mark - Click to get weather
-(void)enterForeground {
[self.locationManager startUpdatingLocation];
}
#pragma mark - CLLocationManagerDelegate
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
NSLog@"didUpdateLocations";
}
但是,enterForeGround 确实会在我进入前台时被调用,但 didUpdateLocations 不会一直被调用。
我不知道我错过了位置服务的一些关键内容。如果您有任何想法,请给我建议。
谢谢
【问题讨论】:
标签: objective-c ios5 core-location viewwillappear