GPS位置权限框未显示

时间:2016-01-28 09:47:41

标签: iphone xcode permissions gps

我正在尝试创建一个gps位置应用,它可以获取用户的纬度和经度。我想在用户启动应用时请求该位置。

if([self.locationManager                                                                     
      respondsToSelector:@selector(requestWhenInUseAuthorization)])
{

    [self.locationManager requestWhenInUseAuthorization];
}

else

{

    [self.locationManager startUpdatingLocation];
}

但它没有帮助我也尝试

    if([CLLocationManager locationServicesEnabled]){

    NSLog(@"Location Services Enabled");

    if([CLLocationManager authorizationStatus]==kCLAuthorizationStatusDenied){
        UIAlertView    *alert = [[UIAlertView alloc] initWithTitle:@"App Permission Denied"
                                                           message:@"To re-enable, please go to Settings and turn on Location Service for this app."
                                                          delegate:nil
                                                 cancelButtonTitle:@"OK"
                                                 otherButtonTitles:nil];
        [alert show];
    }
}

它也没有帮助。

1 个答案:

答案 0 :(得分:0)

您需要为位置请求添加密钥 您的plist文件中的NSLocationWhenInUseUsageDescription 和NSLocationAlwaysUsageDescription键,如果你想在后台定位。