How to make my ios app appears in Location Services in the settings

陌路散爱 提交于 2019-12-24 14:16:14

问题


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!


回答1:


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




回答2:


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];
    }
}


来源:https://stackoverflow.com/questions/11069018/how-to-make-my-ios-app-appears-in-location-services-in-the-settings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!