ios8的CLLocationManager代码不适用于ios7

时间:2014-12-05 14:08:19

标签: ios7 gps ios8 cllocationmanager

之前我使用了一个简单的代码(我没有在这里发布)用于gps跟踪,它在iPhone 4上工作得非常好。目前我在viewcontroller.m中使用以下代码来获取当前的gps位置:

- (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");
         }

     }];
}

我使用此link来支持iPhone 6的gps跟踪。此代码获取 iPhone 6和iPhone 4S 上的当前gps位置,但不支持 iPhone 5S和iPhone 6 Plus 。我想知道为什么会这样?

0 个答案:

没有答案