系統定位在iOS8中的改變

來源:互聯網
上載者:User

標籤:des   style   blog   http   io   ar   os   sp   檔案   

CLLocationManager這個系統定位的類在iOS8之前要實現定位,只需要遵守CLLocationManagerDelegate這個代理即可:

- (void)startLocate

{  

     if([CLLocationManager locationServicesEnabled]){

        _locManager = [[CLLocationManager alloc]init];

         [self.locManager setDelegate:self];

        [self.locManager setDesiredAccuracy:kCLLocationAccuracyBest];

        [self.locManager startUpdatingLocation];

    }

}

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations

{

  [_locManager stopUpdatingLocation];

    CLLocation *currentLocation = [locations lastObject];

    CLLocationCoordinate2D coor = currentLocation.coordinate;

    NSString *latitude =  @(coor.latitude).description;

    NSString *longitude = @(coor.longitude).description;

}

iOS8之前以上兩個方法正常的情況下,已經能夠正常擷取經緯度了。但是在iOS8下,則需要在startLocate這個方法中在CLLocationManager這個類執行個體化後添加如下代碼:

        if([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)

        {

            [ self.locManager requestAlwaysAuthorization];

        }

但是僅僅添加以上代碼還不行,還需要在工程的info.plist檔案中添加索引值對:

                  Key                                                                        Type                                                      Value

NSLocationAlwaysUsageDescription              Array/Dictionary/Boolean/Data/Date/Number/String              

注意上方對應的Type,這七種類型都支援,我重點說說String和Boolean類型:

1.Type為String時:Value這個地方開發人員可以根據需要說明定位的具體目的,讓使用者清楚的知道開啟定位後用於做什麼,更加透明化,清晰化;

彈框中"定位"兩字即為Type為String時Value設定的值為"定位"時的展示。

當Value的值為空白時,彈框顯示如下:

 

2.Type為Boolean時:Value填YES即可。彈框顯示如下:

 

而iOS8以前,定位提示的彈框顯示如下:

 在iOS8下如果不做以上兩處的處理,系統CLLocationManager這個類即時指定了代理,其擷取經緯度的代理方法也不會走。

系統定位在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.