简体   繁体   English

如何根据iOS中的位置服务状态重定向到视图控制器

[英]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.

相关问题 iOS 7:如何在一个视图控制器中将状态栏文本颜色更改为白色,在第二个视图控制器中将状态栏文本颜色更改为黑色? - iOS 7 : How to change the status bar text color as white in one view controller and black in second view controller? iOS定位服务-是否可以通过编程方式设置位置感知应用程序的授权状态? - iOS Location Services - Is there any way to set the authorization status of a location-aware application programmatically? iOS 6中的ALAssetsLibrary和Location Services - ALAssetsLibrary and Location Services in iOS 6 如何在iOS 8中为自定义呈现的视图控制器处理调用(双高)状态栏的布局? - How to do layout to handle in-call (double-height) status bar for custom presented view controller in iOS 8? 如何使定位服务图标从状态栏中消失? - How to make Location Services icon disappear from Status Bar? ios如何将自定义控制器重定向obj-c代码放入自定义视图 - ios How to put custom controller redirect obj-c code in custom view ios 7中显示模型视图控制器时出现状态栏问题 - status bar issue while presenting model view controller in ios 7 如何根据远程通知在ios应用程序中更改初始视图控制器? - How do you change the initial view controller in an ios application based on a remote notification? 如何在iOS 4.2之前检查是否为特定应用启用了位置服务? - How to check if location services are enabled for a particular app prior to iOS 4.2? 如何使用 swift 在 iOS 中打开位置服务页面? - How to open Location Services page in iOS using swift?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM