Pri*_*202 7 location map cllocationmanager ios
我正在开发一个基于地图和位置跟踪的iOS应用程序.当用户首次启动应用程序时,它会要求获得跟踪位置等的权限.唯一的问题是,当它正在这样做时,我有代码在用户点击OK 之前设置初始地图视图和其他基于位置的变量.
我发现我可以在等待用户更改位置管理器的权限的while循环之后放置这些启动步骤,但这不可能是最好的做法,更不用说它会导致一些奇怪的行为启动画面和地图:
BOOL firstrun = TRUE;
while ([[locationManager class] authorizationStatus] == kCLAuthorizationStatusDenied || [[locationManager class] authorizationStatus] == kCLAuthorizationStatusNotDetermined) {
NSLog(@"Waiting for location permission");
}
...initiation code...
Run Code Online (Sandbox Code Playgroud)
警报框是否有"位置访问权限"监听器或者我不知道的位置管理器委托中的类似功能?我在文档中看不到这样的方法.谁知道最好的做法是什么?非常感谢.
编辑 我开始我的位置跟踪如下:
if (nil == locationManager)
locationManager = [[CLLocationManager alloc] init];
[locationManager startMonitoringSignificantLocationChanges];
self.musicmap.delegate = self;
[self.mymap setShowsUserLocation:true];
Run Code Online (Sandbox Code Playgroud)
谢谢
小智 8
我建议你的类成为CLLocationManagerDelegate,然后实现这个方法:
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
//Your code goes here
}
Run Code Online (Sandbox Code Playgroud)
有关CLLocationManagerDelegate的更多信息,请访问此处.
希望有所帮助!