我正在尝试创建一个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];
}
}
它也没有帮助。
答案 0 :(得分:0)
您需要为位置请求添加密钥 您的plist文件中的NSLocationWhenInUseUsageDescription 和NSLocationAlwaysUsageDescription键,如果你想在后台定位。