ios - 如何检查位置服务并启动不同的 View ?

标签 ios uiviewcontroller core-location cllocationmanager uistoryboard

我想检查我的应用程序启用或禁用位置服务。因此,如果定位服务被禁用,我会启动不同的 View 。我如何使用一个 Storyboard来做到这一点?我需要一个示例代码。

My Storyboard

Segue 标识符(例如 GPS View ):

segue identifier

我的代码:

- (void)viewDidLoad
{
    [super viewDidLoad];

    if([CLLocationManager locationServicesEnabled]){

        NSLog(@"Konum Servisleri Açık");

        if([CLLocationManager authorizationStatus]==kCLAuthorizationStatusDenied){
            alert = [[UIAlertView alloc] initWithTitle:@"Konum Servisleri Kapalı" message:@"Etkinleştirmek için ayarlardan konum servislerini kullanmasına izin verin." delegate:nil cancelButtonTitle:@"Tamam" otherButtonTitles:nil];
            [alert show];
            segueKontrol = @"Normal";
            [self performSegueWithIdentifier:@"Normal" sender:self];
        }
        else{
            segueKontrol = @"GPS";
            [self performSegueWithIdentifier:@"GPS" sender:self];
        }
    }

    else{
        NSLog(@"Konum Servisleri Kapalı");
        alert = [[UIAlertView alloc] initWithTitle:@"Konum Servisleri Kapalı" message:@"Etkinleştirmek için ayarlardan Konum Servislerini etkinleştirin." delegate:nil cancelButtonTitle:@"Tamam" otherButtonTitles:nil];
        [alert show];

        segueKontrol = @"Normal";
        [self performSegueWithIdentifier:@"Normal" sender:self];
    }

    // Do any additional setup after loading the view, typically from a nib.
}

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{

    if ([[segue identifier] isEqualToString:@"Normal"])
    {
        CCHop2ViewController *cc = [segue destinationViewController];
    }
    else{
     CCHopViewController *cc = [segue destinationViewController];
    }

}

最佳答案

首先,在 Storyboard中用唯一的名称命名你的 2 个 segue,比如 AB 在您的第一个 View Controller (处理最左边 View 的那个)中,执行此操作:

if (([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorized) &&
            [CLLocationManager locationServicesEnabled]) {
  [self performSegueWithIdentifier:@"A" sender:self];
} else {
  [self performSegueWithIdentifier:@"B" sender:self];
}

关于ios - 如何检查位置服务并启动不同的 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15405399/

相关文章:

ios - UIScrollView 不起作用(无法滚动)

ios - UIView 子类不能使用 UIView 自定义类?

ios - 关闭所有打开的 View Controller 的单一功能

iphone - 从其他 ViewController 的 locationManager 方法访问 newLocation

GPS报告精度、误差函数

ios - UIBackgroundModes 带有位置值,然后应用程序被拒绝

ios - Xcode 9.3.1 组件列表为空,无法下载 iOS 10 模拟器

ios - 大型 uitableview(1000 行)在 reloadData() 上卡住

ios - 如何从不在 Storyboard 中但以编程方式创建的 View Controller 呈现 "main" Storyboard 中的 View Controller ?

objective-c - 使用 iOS 7 UIViewController 过渡动画放松超过 1 个 segue