iOS8定位

在IOS8中定位功能新增了两个方法:php

- (void)requestWhenInUseAuthorization __OSX_AVAILABLE_STARTING(__MAC_NA, __IPHONE_8_0);- (void)requestAlwaysAuthorization __OSX_AVAILABLE_STARTING(__MAC_NA, __IPHONE_8_0);

这两个新增的方法致使,以前写的程序在iOS8运行会出现,定位功能没法正常使用
html

这样让iOS8正常使用定位功能呢?ui

<1>你须要在info.plist表里面添加两条变量url

在Info.plist中加入两个缺省没有的字段
spa

  • NSLocationAlwaysUsageDescription代理

  • NSLocationWhenInUseUsageDescriptioncode

这两个字段没什么特别的意思,就是自定义提示用户受权使用地理定位功能时的提示语。orm



这样在写代码:
htm

    CLLocationManager  *locationManager = [[CLLocationManager alloc]init];    locationManager.delegate = self;    [locationManager requestAlwaysAuthorization];    locationManager.desiredAccuracy = kCLLocationAccuracyBest;    locationManager.distanceFilter = kCLDistanceFilterNone;    [locationManager startUpdatingLocation];



这是在调用代理ip


- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {    switch (status) {        case kCLAuthorizationStatusNotDetermined:            if ([locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {                [locationManager requestWhenInUseAuthorization];            }            break;        default:            break;    }}



这样就Ok了,就会弹出原来的提示框

相关文章
相关标签/搜索