shows user location在iOS8上不能使用地圖定位

來源:互聯網
上載者:User

shows user location在iOS8上不能使用地圖定位

在xcode6中 蘋果地圖得定位方法修改了,以前得不能用了

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

解決辦法:

在Supporting Files下得XXX.info.plis裡面添加NSLocationAlwaysUsageDescription 或 NSLocationWhenInUseDescription 兩個String欄位,value可以為空白,也可以設定YES,不過我得問題還是不能解決,最終還是找到得了問題所在,就是info.plist中還需要包含Supported interface orientations 這個Array欄位。然後運行就解決了.


代碼處理:

locationManager = [[CLLocationManager alloc] init];        locationManager.delegate = self;        locationManager.desiredAccuracy=kCLLocationAccuracyBest;        if([locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {            [locationManager requestWhenInUseAuthorization];        }        [locationManager startUpdatingLocation];

另外一處:

- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {    if (        ([locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)] && status != kCLAuthorizationStatusNotDetermined && status != kCLAuthorizationStatusAuthorizedWhenInUse) ||        (![locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)] && status != kCLAuthorizationStatusNotDetermined && status != kCLAuthorizationStatusAuthorized)        ) {        NSString *message = @"您的手機目前未開啟定位服務,如欲開啟定位服務,請至設定開啟定位服務功能";        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"無法定位" message:message delegate:nil cancelButtonTitle:@"確定" otherButtonTitles: nil];        [alertView show];    }else {        [locationManager startUpdatingLocation];    }}

上面那行是 iOS 8 以上,第二行是 iOS 7 以下, kCLAuthorizationStatusAuthorized 在 iOS 8 完全不能使用。

別的地方:

CLAuthorizationStatus status = [CLLocationManager authorizationStatus];        if (status == kCLAuthorizationStatusAuthorizedWhenInUse || status == kCLAuthorizationStatusAuthorized) {    // 開始定位}else {    // 提示警告}
代碼修改片段來源於此:http://blog.dreambreakerx.com/tag/ios/

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.