2015-10-31 33 views
-1

我正在使用下面的代码来显示用户在iOS 8.4中的当前位置。我想在iOS 8.4中获取用户的当前位置,但它不工作,我正在使用此代码

- (void)viewDidLoad 
    {   
     [super viewDidLoad]; 

     [locationManager requestAlwaysAuthorization]; 
     self.mapView.delegate = self; 
     [self.mapView setShowsUserLocation:YES]; 
     locationManager = [[CLLocationManager alloc] init]; 
     locationManager setDelegate:self]; 
     [locationManager setDistanceFilter:kCLDistanceFilterNone]; 
     [locationManager setDesiredAccuracy:kCLLocationAccuracyBest]; 

    } 

但它工作不正常。它显示以下错误:

Trying to start MapKit location updates without prompting for location authorization. Must call -[CLLocationManager requestWhenInUseAuthorization] or -[CLLocationManager requestAlwaysAuthorization] first.

+0

的可能的复制[iOS 8的requestWhenInUseAuthorization没有弹出](http://stackoverflow.com/questions/24850128/ios-8-requestwheninuseauthorization-no-popup) –

回答

0

为了获取用户当前位置,您需要在项目info.plist文件中添加一个字符串作为字符串。

重点是: NSLocationAlwaysUsageDescription

相关问题