- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation{
static int i=0;
if([self getCurrentLocation]==nil){
i++;
if(i>3){
[[self locationManager] stopUpdatingLocation];
useMyLocation = NO;
[self locationUpdated];
}
}else{
[self locationUpdated];
}
}
- (void)alertView:(UIAlertView *)anAlertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if(buttonIndex==1){
self.useMyLocation = YES;
[[self locationManager] startUpdatingLocation];
}else{ // buttonIndex==0
self.useMyLocation = NO;
[self locationUpdated];
}
}
这是 ios 4 和 5 中的工作代码。我的问题是我无法获得在 ios 6 中工作的位置。该应用程序甚至不征求用户的许可。阅读后这是我迄今为止尝试过的:
CFBundleDisplayName 解决方案。我的 plist 中已经有了 CFBundleDisplayName。我尝试删除它并再次添加它 - 不行。
将 Location Manager 的属性 pausesLocationUpdatesAutomatically 设置为 NO,如下所示:
...
- (CLLocationManager *)locationManager{
if (locationManager != nil){
return locationManager;
}
CLLocationManager *tmp = [[CLLocationManager alloc] init];
tmp.pausesLocationUpdatesAutomatically = NO; //!@#
[self setLocationManager:tmp];
[tmp release];
[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
[locationManager setDelegate:self];
return locationManager;
}
我也读过locationManager:didUpdateLocations:
,我不知道如何在代码中实现它,我也不确定这是否是解决方案。