ios8的CLLocationManager代码在ios7中不起作用
之前我使用了一个简单的代码,我没有在这里发布用于gps跟踪的代码,它在iPhone4上运行得非常好。目前,我在viewcontroller.m中使用以下代码获取当前gps位置:ios8的CLLocationManager代码在ios7中不起作用,ios7,gps,ios8,cllocationmanager,Ios7,Gps,Ios8,Cllocationmanager,之前我使用了一个简单的代码,我没有在这里发布用于gps跟踪的代码,它在iPhone4上运行得非常好。目前,我在viewcontroller.m中使用以下代码获取当前gps位置: - (void)viewDidLoad { [super viewDidLoad]; [self CurrentLocationIdentifier]; } -(void)CurrentLocationIdentifier { locationManager = [CLLocationManag
- (void)viewDidLoad {
[super viewDidLoad];
[self CurrentLocationIdentifier];
}
-(void)CurrentLocationIdentifier
{
locationManager = [CLLocationManager new];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
if (IS_OS_8_OR_LATER)
{
[locationManager requestWhenInUseAuthorization];
[locationManager requestAlwaysAuthorization];
}
if ([locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
[locationManager requestWhenInUseAuthorization];
}
[locationManager startMonitoringSignificantLocationChanges];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
current = [locations objectAtIndex:0];
[locationManager stopUpdatingLocation];
CLGeocoder *geocoder = [[CLGeocoder alloc] init] ;
[geocoder reverseGeocodeLocation:current completionHandler:^(NSArray *placemarks, NSError *error)
{
if (!(error))
{
CLPlacemark *placemark = [placemarks objectAtIndex:0];
NSLog(@"\nCurrent Location Detected\n");
NSLog(@"placemark %@",placemark);
NSString *locatedAt = [[placemark.addressDictionary valueForKey:@"FormattedAddressLines"] componentsJoinedByString:@", "];
NSString *Address = [[NSString alloc]initWithString:locatedAt];
NSString *Area = [[NSString alloc]initWithString:placemark.locality];
NSString *Country = [[NSString alloc]initWithString:placemark.country];
NSString *CountryArea = [NSString stringWithFormat:@"%@, %@", Area,Country];
NSLog(@"Address: %@", Address);
NSLog(@"CountryArea: %@",CountryArea);
}
else
{
NSLog(@"Geocode failed with error %@", error);
NSLog(@"\nCurrent Location Not Detected\n");
}
}];
}
我用它来支持iPhone 6的gps跟踪。这段代码在iPhone 6和iPhone 4S上获取当前gps位置,但在iPhone 5S和iPhone 6 Plus中没有。我想知道为什么会发生这种情况 不要同时调用RequestWhenUseAuthorization和requestAlwaysAuthorization;只选一个@托尼姆基努:谢谢!!!你找到答案了吗?@简单地告诉我:是的,不要使用[locationManager RequestWhenUseAuthorization];[locationManager请求始终授权];同时