Я пытаюсь получить текущее местоположение пользователя с помощью Core Location Framework в Xcode 6.3.1, я следующие вещи:Основные методы Местоположение делегат не вызывался в прошивкой 8.3 Xcode 6.3.1
- Добавлено Core Location Framework под Target ->Общие ->Linked Каркасы & Библиотеки
Мои ViewController.h файл, как показано ниже,
#import <UIKit/UIKit.h> #import <CoreLocation/CoreLocation.h> @interface ViewController : UIViewController<CLLocationManagerDelegate> @property (weak, nonatomic) IBOutlet UILabel *lblLatitude; @property (weak, nonatomic) IBOutlet UILabel *lblLongitude; @property (weak, nonatomic) IBOutlet UILabel *lblAddress; @property (strong, nonatomic) CLLocationManager *locationManager; @end
Мой файл ViewController.m как показано ниже,
- (void)viewDidLoad { [super viewDidLoad]; self.locationManager = [[CLLocationManager alloc] init]; self.locationManager.delegate = self; if(IS_OS_8_OR_LATER){ NSUInteger code = [CLLocationManager authorizationStatus]; if (code == kCLAuthorizationStatusNotDetermined && ([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)] || [self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)])) { if([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationAlwaysUsageDescription"]){ [self.locationManager requestAlwaysAuthorization]; } else if([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationWhenInUseUsageDescription"]) { [self.locationManager requestWhenInUseAuthorization]; } else { NSLog(@"Info.plist does not contain NSLocationAlwaysUsageDescription or NSLocationWhenInUseUsageDescription"); } } } [self.locationManager startUpdatingLocation]; } #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) { lblLatitude.text = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.longitude]; lblLongitude.text = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.latitude]; } } @end
Я также добавил следующие ключи в моем файле info.plist
- NSLocationWhenInUseUsageDescription
- NSLocationAlway sUsageDescription
Checked все дано here, here, here, here, и многое другое список
Итак, любое лицо, имеющее решение для этой проблемы, пожалуйста, помогите. Я потерял рассудок в поисках этого в течение всего дня.
Значения для описания использования пустые. Вы уверены, что положили их? Также почему у вас есть два описания использования? –
@VinhNguyen Я тоже пытался помещать значения в это, но это не влияет, и, сохраняя только NSLocationAlwaysUsageDescription, также и это не работает для меня. Пробовал это тоже ... – iYoung
Попробуйте удалить if if if (code == kCLAuthorizationStatusNotDetermined && .... 'и просто вызвать либо' requestAlwaysAuthorization', либо 'requestWhenInUseAuthorization' на вашем экземпляре' locationManager' –