CLLocationManagerDelegate不調用didUpdateLocations (地圖),cllocationmanager

來源:互聯網
上載者:User

CLLocationManagerDelegate不調用didUpdateLocations (地圖),cllocationmanager
這是因為xcode升級造成的定位使用權限設定問題。
升級xcode6以後開啟以前xcode5工程,程式不能定位。工程升級到xcode6編譯時間需要iOS8 要自己寫授權,不然沒許可權定位。
解決方案:
首先在 info.plist裡加入對應的預設欄位 ,值設定為YES(前台定位寫上邊欄位,前後台定位寫下邊欄位)
          NSLocationWhenInUseUsageDescription   //允許在前台擷取GPS的描述
          NSLocationAlwaysUsageDescription   //允許在前、後台擷取GPS的描述 
後方附圖

先上代碼:
?

123456789101112131415161718192021222324252627282930313233343536 #import "ViewController.h"#import <CoreLocation/CoreLocation.h>@interface ViewController ()<CLLocationManagerDelegate>@property (nonatomic, strong) CLLocationManager *locationManager;@end @implementation ViewController //    1. 懶載入初始化:- (CLLocationManager *)locationManager{    if(!_locationManager){        self.locationManager = [[CLLocationManager alloc] init];        self.locationManager.delegate = self;    }    return _locationManager;} - (void)viewDidLoad {    [super viewDidLoad]; //    2. 調用請求:    if ([[[UIDevice currentDevice] systemVersion] doubleValue] > 8.0)    {        //設定定位許可權 僅ios8有意義        [self.locationManager requestWhenInUseAuthorization];// 前台定位                 //  [locationManager requestAlwaysAuthorization];// 前後台同時定位    }    [self.locationManager startUpdatingLocation];} // 3.代理方法- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{    NSLog(@"%ld",locations.count);}@end



     圖片:圖.png 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.