iOS8的定位,始终开启还是应用运行时开启

原文  http://blog.csdn.net/nextstudio/article/details/40050095

 

http://www.tuicool.com/articles/VN3632

 

 

1、修改info

新增Key: NSLocationAlwaysUsageDescription 和 NSLocationWhenInUseUsageDescription ,这两个Key的值将分别用于描述应用程序始终使用和使用期间使用定位的说明,这些说明将显示在用户设置中。

info新增键值对如下 :

应用程序说明参见微信:

2、CLLocationManager初始化

iOS8CLLocationManager新增实例方法 requestWhenInUseAuthorization和 requestAlwaysAuthorization,需要在初始化时根据需要调用。

 

if([CLLocationManager locationServicesEnabled]){
self.locationManage = [[[CLLocationManager alloc] init] autorelease];
self.locationManage.delegate = self;
self.locationManage.distanceFilter = 200;
self.locationManage.desiredAccuracy = kCLLocationAccuracyBestForNavigation;//kCLLocationAccuracyBest;
if (SYSTEM_VERSION >= 8.0) {
    //使用期间
    [self.locationManage requestWhenInUseAuthorization];
    //始终
    //or [self.locationManage requestAlwaysAuthorization]
}
    }

3、代理

新增下面的代理方法:

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

}



定位:iOS9 有蓝条。。退出后台,不定位的话,过会就自动去掉蓝条。定位也没用了。,如果一直定位,蓝条不取消。。

Info 里面 :  Required background modes              App registers   for location updates      //想要后台定位,必须要

NSLocationWhenInUseUsageDescription               ------只有这个会出现蓝条         [_locationManager stopUpdatingLocation];//蓝条就会消失。

 

if([[[UIDevice currentDevice] systemVersion] floatValue] >= 9.0){

        [[[CyclingManager ShareInstance] locationManager] setAllowsBackgroundLocationUpdates:YES];//todo-张明炜

    }

        _locationManager = [[CLLocationManager alloc] init];

        _locationManager.pausesLocationUpdatesAutomatically = NO;   // 该值默认为YES,设置为NO,保持定位更新

        if(IS_IOS8) {

//            [_locationManager requestAlwaysAuthorization];//NSLocationAlwaysUsageDescription  保持一致 

            [_locationManager requestWhenInUseAuthorization];//NSLocationWhenInUseUsageDescription  保持一致。

        }

        _locationManager.delegate = self;

        _locationManager.desiredAccuracy = kCLLocationAccuracyBest;

        

//        [_locationManager startMonitoringSignificantLocationChanges];

 

——————————————————————没用蓝条----

NSLocationAlwaysUsageDescription              这样没用蓝条,,    [_locationManagerstopUpdatingLocation];//就可以取消右上角的定位符号。,,

 

项目中遇到了  stopUpdatingLocation iOS8 的蓝条依然存在。。。一种可能是 还有其他的地方没用stop。。。。   另一中情况是  引入了其他的定位框架,例如mapBox  等。

 

上面的代码  测试过了。没用问题。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值