zoukankan      html  css  js  c++  java
  • 关于iOS开发CLLocation中定位的一些小问题

    困扰了我一周的CLLocation定位问题终于解决了,网上的很多关于CLLocation的文章都是iOS 7 的,按照上面的指导,仍然不能够调出定位功能,对于iOS 8 是需要作额外的添加的,废话不多说

    1.首先,需要再 infoplist文件中 添加两个键:

    1
    2
        NSLocationWhenInUseUsageDescription  :当app在前台的时候,才可以获取到定位信息
        NSLocationAlwaysUsageDescription     :app在前台、后台、挂起、结束进程状态时,都可以获取到定位信息

    2.添加一个
    xcode->File->New->File,选择String File,命名为InfoPlist.strings,然后对此文件国际化:

    第一句加入到中文Infoplist.strings,第二句加入到英文Infoplist.strings

      

    3.最后加上这个:

      [super viewDidLoad];
        self.view.backgroundColor =[UIColor greenColor];
        self.mgr = [[CLLocationManager alloc] init];
        
        self.mgr.delegate = self;

        
        
        
        [self.mgr requestWhenInUseAuthorization];//相对应info.plist中的NSLocationWhenInUseUsageDescription键
        [self.mgr requestAlwaysAuthorization];
        
        [self.mgr startUpdatingLocation];

    大功告成,可以弹出询问用户,获取定位权限。


       

  • 相关阅读:
    hdu 1028 Ignatius and the Princess III (n的划分)
    CodeForces
    poj 3254 Corn Fields (状压DP入门)
    HYSBZ 1040 骑士 (基环外向树DP)
    PAT 1071 Speech Patterns (25)
    PAT 1077 Kuchiguse (20)
    PAT 1043 Is It a Binary Search Tree (25)
    PAT 1053 Path of Equal Weight (30)
    c++ 常用标准库
    常见数学问题
  • 原文地址:https://www.cnblogs.com/YaoWang/p/4825701.html
Copyright © 2011-2022 走看看