0

ユーザーがアプリに自分の場所の使用を許可しているかどうかを確認したいビューコントローラーがあります。受け入れる場合、アプリはRootViewControllerからOffersViewControllerに移動し、拒否する場合は、OffersNoGPSViewControllerにセグエする必要があります。

現時点では、ユーザーが「許可しない」と言った場合に「OK」と言った場合は機能し、RootViewControllerに残ります。

また、「OK」をタッチしてアプリがその位置を使用できるようにした後、OffersViewControllerに移動すると、この「外観の開始/終了の不均衡な呼び出し」という警告が表示されます。

助けてくれてありがとう。これが私のコードです:

- (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 if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied)

    [self performSegueWithIdentifier: @"SegueOffersNoGPS" sender: self];


}

- (void)locationError:(NSError *)error {
    locLabel.text = [error description];
}


- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"SegueOffersNoGPS"])
    {
        OffersViewController *vc = [segue destinationViewController];
        //vc.dataThatINeedFromTheFirstViewController = self.theDataINeedToPass;

        NSLog(@"auth status no GPS");
    }

    if ([[segue identifier] isEqualToString:@"SegueOffersGPS"])
    {
        OffersViewController *vc = [segue destinationViewController];


        //vc.dataThatINeedFromTheFirstViewController = self.theDataINeedToPass;


        NSLog(@"auth status is GPS");

    }
}

私の完全なRootViewControllerコード:

  @interface RootViewController ()

@end

@implementation RootViewController
@synthesize CLController;


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

}

-(void) viewWillAppear:(BOOL)animated {

    CLController = [[CoreLocationController alloc] init];
    CLController.delegate = self;
    [CLController.locMgr startUpdatingLocation];

    NSLog(@"RootViewController");

    [CLController.locMgr startUpdatingLocation];
//    
//    if ([CLLocationManager authorizationStatus] ==3) {
//        [self performSegueWithIdentifier: @"SegueOffersGPS" sender: self];
//        
//        
//    }
//    if ([CLLocationManager authorizationStatus] !=3) {
//        [self performSegueWithIdentifier: @"SegueOffersNoGPS" sender: self];
//    }

}

-(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {

    if (status == kCLAuthorizationStatusDenied) {
        // denied
        [self performSegueWithIdentifier: @"SegueOffersNoGPS" sender: self];
        [CLController.locMgr stopUpdatingLocation];


    }
    else if (status == kCLAuthorizationStatusAuthorized) {
        // allowed
        [self performSegueWithIdentifier: @"SegueOffersGPS" sender: self];
        [CLController.locMgr stopUpdatingLocation];
    }
}

- (void)locationUpdate:(CLLocation *)location {
    //locLabel.text = [location description];

    NSLog(@"auth status is %u", [CLLocationManager authorizationStatus]);

    if ([CLLocationManager authorizationStatus] ==3) {
        [self performSegueWithIdentifier: @"SegueOffersGPS" sender: self];

    }
    if ([CLLocationManager authorizationStatus] !=3) {
        [self performSegueWithIdentifier: @"SegueOffersNoGPS" sender: self];

    }      
}

- (void)locationError:(NSError *)error {

    [self performSegueWithIdentifier: @"SegueOffersNoGPS" sender: self];

}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"SegueOffersNoGPS"])
    {
        self.navigationController.toolbarHidden=YES;

        NSLog(@"auth status no GPS");
    }

    if ([[segue identifier] isEqualToString:@"SegueOffersGPS"])
    {
        self.navigationController.toolbarHidden=NO;

        NSLog(@"auth status is GPS");

    }
}

-(void)viewDidDisappear:(BOOL)animated {

    [CLController.locMgr stopUpdatingLocation];

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
4

1 に答える 1

2

ユーザーが位置情報サービスを許可しない場合、位置情報更新メソッドが呼び出されることはなく、ステータスのチェックも行われません。CLLocationManagerDelegateのlocationManager:didChangeAuthorizationStatus:メソッドを実装してみてください。ユーザーが「位置情報サービスを許可する」アラートで「はい」または「いいえ」を選択すると呼び出されます。

于 2013-01-31T05:14:56.273 に答える