iOS等待位置管理器初始化 [英] iOS Waiting for Location Manager to Init

查看:135
本文介绍了iOS等待位置管理器初始化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发基于地图和位置跟踪的iOS应用。当用户首次启动应用程序时,它会要求获得跟踪位置等的权限。唯一的问题是,当它正在这样做时,我有代码设置初始地图视图和其他基于位置的变量用户单击确定之前。

I'm developing an iOS app based on the map and location tracking. When the user first boots the app it asks for permission to track location etc. just fine. The only problem is while it's doing that, I have code setting up the initial map view and other location-based variables before the user has clicked OK.

我发现我可以在等待用户更改位置管理器权限的while循环之后执行这些启动步骤,但这不可能是最佳做法,更不用说它会导致一些奇怪的行为初始屏幕和地图之间的转换:

I've found I can put these initiation steps after a while loop that waits for the user to change the location manager's permissions as below but this can't possibly be best practice, not to mention it leads to some strange behavior in the transition between the splash screen and the map:

BOOL firstrun = TRUE;
while ([[locationManager class] authorizationStatus] == kCLAuthorizationStatusDenied || [[locationManager class] authorizationStatus] == kCLAuthorizationStatusNotDetermined) {
    NSLog(@"Waiting for location permission");
}
...initiation code...

是否有位置访问授予警报框的监听器或位置管理器委托中的类似功能,我不知道?我在文档中看不到这样的方法。谁知道最好的做法是什么?非常感谢你。

Is there a "location access granted" listener for the alert box or a similar function in the location manager delegate I don't know about? I see no such method in the docs. Anyone know what the best practice is here? Thank you so much.

编辑
我按如下方式启动我的位置跟踪:

EDIT I start my location tracking as follows:

if (nil == locationManager)
    locationManager = [[CLLocationManager alloc] init];

[locationManager startMonitoringSignificantLocationChanges];

self.musicmap.delegate = self;
[self.mymap setShowsUserLocation:true];

谢谢

推荐答案

我建议让你的类成为CLLocationManagerDelegate然后实现这个方法:

I would recommend making your class a CLLocationManagerDelegate and then implementing this method:

- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
    //Your code goes here
}

有关CLLocationManagerDelegate的更多信息,请访问这里

More information about CLLocationManagerDelegate can be found here.

希望有所帮助!

这篇关于iOS等待位置管理器初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆