xcode6開啟以前工程在Ios8系統無法定位解決方案

來源:互聯網
上載者:User

標籤:des   style   http   color   io   os   ar   for   sp   

xcode6開啟以前xcode5工程,發現程式不能定位,包括iOS8模擬器,真機都不能定位?代碼經檢查沒有問題,後來尋找蘋果Ios8升級差異策略,發現Ios8對定位處理做了一些調整,工程升級到xcode6編譯時間需要iOS8 要自己寫授權,不然沒許可權定位。修改點如下:
      1: 在Info.plist中加入兩個預設沒有的欄位 ,值均設定為YES
       NSLocationAlwaysUsageDescription
      NSLocationWhenInUseUsageDescription
2:啟動定位代碼[locationManager startUpdatingLocation] 前,需要增加Ios8判斷處理

  if ([[[UIDevice currentDevice] systemVersion] doubleValue] > 8.0) {
            //設定定位許可權 僅ios8有意義
            [locationManager requestAlwaysAuthorization];
        }
        [locationManager startUpdatingLocation];

3:實現 CLLocationManagerDelegate 代理 - (void)locationManagerCLLocationManager *)manager didChangeAuthorizationStatusCLAuthorizationStatus)status 方法,注意:如不增加該代理方法實現,會導致首次調用定位時候無法彈出 ”程式啟動定位提示框“ 導致定位失敗

#pragma mark - 授權定位
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
    
    NSLog(@"調用代理");
    switch (status) {
            
        case kCLAuthorizationStatusNotDetermined:{
            
            if ([locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
                [locationManager requestWhenInUseAuthorization];
            }
        }
            break;
        default:{
            
        }
            break;
    }
}

 

xcode6開啟以前工程在Ios8系統無法定位解決方案

聯繫我們

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