1

I wrote an CLLocationManager ios app. However, I cannot see my app appears in the Location Services in the settings on my iPhone. Do I need to set a specific value in plist in my ios project in Xcode? Thanks in advance!

flyingbin
  • 1,097
  • 2
  • 11
  • 28

2 Answers2

2

It should appear automatically once code that actually requires location tracking is being called (whenever the popup first show: do you allow...)

try calling something like this:

[self.locationManager startUpdatingLocation];

And that should do it

JP Hribovsek
  • 6,707
  • 2
  • 21
  • 26
0

In iOS -8 need to do some changes :

locationManager = [[CLLocationManager alloc] init];
    locationManager.delegate = self;
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    if([locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]){
        [locationManager requestWhenInUseAuthorization];
    }else{
        [locationManager startUpdatingLocation];
    }

need to add 2 extra key in plist with blank value 1)NSLocationWhenInUseUsageDescription 2)NSLocationAlwaysUsageDescription

#pragma mark - CLLocationManagerDelegate

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
    NSLog(@"didFailWithError: %@", error);
    UIAlertView *errorAlert = [[UIAlertView alloc]
                               initWithTitle:@"Error" message:@"Failed to Get Your Location" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [errorAlert show];
}

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    NSLog(@"didUpdateToLocation: %@", newLocation);
    CLLocation *currentLocation = newLocation;

    if (currentLocation != nil) {
        NSString *strLat = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.longitude];
        NSString *strLong = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.latitude];
    }
}
Alok
  • 24,880
  • 6
  • 40
  • 67