前言
最近发现一个问题,自iOS 10.0以后,项目中老是出现有关定位管理者的日志信息,说定位管理者最好放在主线程;在实际开发中,当在子线程中创建定位管理者,有可能收不到回调信息
提示信息如下:

A location manager (0x7fbafac12560) was created on a dispatch queue executing on a thread other than the main thread. It is the developer's responsibility to ensure that there is a run loop running on the thread on which the location manager object is allocated. In particular, creating location managers in arbitrary dispatch queues (not attached to the main queue) is not supported and will result in callbacks not being received.
中文翻译为:一个定位管理者创建在子线程,而不是主线程.在开发中,要确保一个定位管理者所在的线程要在运行循环(Run loop)中.在实际开发中,当在子线程中创建定位管理者,有可能收不到回调信息.
解决过程
我找了好久,尝试了好多方法,都无果: 这是在stackoverflow中搜到的解决方法
作者的问题:

比较好的回答:


但我尝试了,也无果.
没办法,有时间了就去尝试.
解决方法:
最终解决方法是在App Delegate 内关于地图或者导航注册信息那一块.
这是我导航注册代码:
//开启导航服务
[BNCoreServices_Instance initServices:@"xxxxxxxxxxxx"];
[BNCoreServices_Instance startServicesAsyn:^{
NSLog(@"导航开启成功");
} fail:^{
NSLog(@"导航开启失败");
}];
我在开启导航服务的时候,使用了异步开启,然后主线程回调开启的结果.
进入百度导航API发现:
/**
* 启动服务,同步方法,会导致阻塞
* @param SoundDelete [in]传入遵守BNSoundManagerProtocol的实例
* @return 启动结果
*/
- (BOOL)startServices;
/**
* 启动服务,异步方法
*
* @param success 启动成功后回调 success block
* @param fail 启动失败后回调 fail block
*/
-(void)startServicesAsyn:(void (^)(void))success fail:(void (^)(void))fail;










