美文网首页
定位 蓝条:

定位 蓝条:

作者: FlyTheKite | 来源:发表于2016-11-15 14:32 被阅读16次

解决了:
1,
info.plist 里面,选用 Privacy - Location When In Use Usage Description;

2,
targets 的 Background Modes, 取消 勾选 Location updates.

3,
在 YMJMainModel.m 的地理 信息 配置 中,

  • (void)configLocationManager
    {

注释
// [self.locationManager setAllowsBackgroundLocationUpdates:YES];//deng

就好了

 转载

iOS 9后台定位崩溃问题

2016-06-06 14:31 214人阅读 评论(0) 收藏 举报

如果不适配iOS9,就不能偷偷在后台定位(不带蓝条,见图)!好消息:将允许出现这种场景:同一App中的多个location manager:一些只能在前台定位,另一些可在后台定位,并可随时开启或者关闭特定location manager的后台定位。

// 1. 实例化定位管理器

_locationManager = [[CLLocationManager alloc] init];

// 2. 设置代理

_locationManager.delegate = self;

// 3. 定位精度

[_locationManager setDesiredAccuracy:kCLLocationAccuracyBest];

// 4.请求用户权限:分为:?只在前台开启定位?在后台也可定位,

//注意:建议只请求?和?中的一个,如果两个权限都需要,只请求?即可,

//??这样的顺序,将导致bug:第一次启动程序后,系统将只请求?的权限,?的权限系统不会请求,只会在下一次启动应用时请求?

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

//[_locationManager requestWhenInUseAuthorization];//?只在前台开启定位

[_locationManager requestAlwaysAuthorization];
//?在后台也可定位

}

// 5.iOS9新特性:将允许出现这种场景:同一app中多个location manager:一些只能在前台定位,另一些可在后台定位(并可随时禁止其后台定位)。

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

_locationManager.allowsBackgroundLocationUpdates = YES;

}

// 6. 更新用户位置

[_locationManager startUpdatingLocation];

但是如果照着这种方式尝试,而没有配置Info.plist,100%你的程序会崩溃掉,并报错:
1

*** Assertion failure
in
-[CLLocationManager setAllowsBackgroundLocationUpdates:]

要将 Info.plist 配置如下:

相关文章

网友评论

      本文标题:定位 蓝条:

      本文链接:https://www.haomeiwen.com/subject/vnzkpttx.html