[英]How to redirect to a view controller based on the status of location services in iOS
I'm using the following code to check to see if the user's location services for the app have changed. 我正在使用以下代码检查用户的应用程序位置服务是否已更改。 If they change they should view a different view controller.
如果他们改变,他们应该查看不同的视图控制器。 It really only needs to run each time the app launches and then redirect based on the
[CLLocationManager authorizationStatus]
status 它实际上只需要在每次启动应用程序时运行,然后根据
[CLLocationManager authorizationStatus]
状态重定向
the problem with my code is that everytime the location updates the segue is ran. 我的代码的问题是每次位置更新时都会运行segue。
thanks for any help 谢谢你的帮助
- (void)locationUpdate:(CLLocation *)location {
//locLabel.text = [location description];
NSLog(@"auth status is %u", [CLLocationManager authorizationStatus]);
if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorized) {
[self performSegueWithIdentifier: @"SegueOffersGPS" sender: self];
} else {
[self performSegueWithIdentifier: @"SegueOffersNoGPS" sender: self];
}
If you want to stop updating location then write below code 如果要停止更新位置,请写下面的代码
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
[self.locationManger stopUpdatingLocation];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.