Melih Mucuk
Melih Mucuk

Reputation: 7066

How can I Check Location Services and Launch Different View?

I want to check location services is enabled or disabled for my app. Accordingly, If location services are disabled, I launch different view. How can I do this with using one storyboard? I need a sample code.

My Storyboard

Segue identifier (for example GPS view's):

segue identifier

my code:

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

}

Upvotes: 0

Views: 130

Answers (1)

Rikkles
Rikkles

Reputation: 3372

First, in the storyboard name your 2 segues with unique names, say A and B In your first view controller (the one handling the leftmost view), do this:

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

Upvotes: 2

Related Questions