如何查看位置服务并启动不同的视图?

时间:2013-03-14 09:24:35

标签: ios uiviewcontroller core-location cllocationmanager uistoryboard

我想检查我的应用是否启用了位置服务。因此,如果禁用位置服务,我会启动不同的视图。如何使用一个故事板来完成此操作?我需要一个示例代码。

My Storyboard

Segue标识符(例如GPS视图):

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];
    }

}

1 个答案:

答案 0 :(得分:2)

首先,在故事板名称中,您的2个segues具有唯一名称,例如AB 在第一个视图控制器(处理最左侧视图的控制器)中,执行以下操作:

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