困扰了我一周的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];

 

 

 

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

 

 

 

 


   

posted on 2015-09-21 11:53  奋斗的王布斯  阅读(262)  评论(0编辑  收藏  举报