ios如何獲取位置權限


 獲取當前位置需要改plist文件  在plist文件加入   NSLocationWhenInUseUsageDescription  字段 

 

  /**

     初始化一個管理器對象

     */

    locationManager = [[CLLocationManager alloc] init];

    /**

     *  設置代理

     */

    locationManager.delegate = self;

    locationManager.desiredAccuracy = kCLLocationAccuracyBest;

    /**

     *  設置移動多遠來獲取一次請求

     */

    locationManager.distanceFilter = 1000.0f;

    

    /**

     *  判斷版本

     *

     *  @param requestWhenInUseAuthorization

     *

     *  @return ios7以上需要寫此方法來獲取當前位置

     */

    if ([locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {

        

        [locationManager requestWhenInUseAuthorization];

    }

    

    /**

     *  開始獲取當前位置

     */

    [locationManager startUpdatingLocation];

    

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM