Мониторинг местоположения в iOS8 не работает

Можете ли вы помочь мне в отношении мониторинга местоположения... Дидентер и Дидексит никогда не называются. Кстати, я тестирую его на iphone. Есть ли что-то еще в коде, который нужно изменить или добавить. Любая помощь приветствуется. благодарю вас.

Ниже приведен код:

- (void)viewDidLoad {

  _manager=[[CLLocationManager alloc]init];

  _mView.delegate=self;

[_manager requestWhenInUseAuthorization];
_manager.delegate=self;

_manager.desiredAccuracy=kCLLocationAccuracyNearestTenMeters;

_manager.distanceFilter=100;

[_manager startUpdatingLocation];
_mView.showsUserLocation=YES;

CLLocationCoordinate2D c;
c.latitude=33.420647;

c.longitude=-111.918893;

c=CLLocationCoordinate2DMake(c.latitude, c.longitude);

CLCircularRegion *circle=[[CLCircularRegion alloc]initWithCenter:c radius:100 identifier:@"string"];

if ([CLLocationManager isMonitoringAvailableForClass:[CLCircularRegion class]]) {

NSLog(@"yes");

[ _manager startMonitoringForRegion:circle];

circle.notifyOnEntry=YES;

circle.notifyOnExit=YES;
}


-(void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region{

    NSLog(@"Inside");

    UIAlertController *alert=[UIAlertController alertControllerWithTitle:@"Monitoring" 
    message:@"Inside" preferredStyle:UIAlertControllerStyleAlert];

    UIAlertAction *action=[UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
}];

    [alert addAction:action];

    [self presentViewController:alert animated:YES completion:nil];

}


-(void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region{

    NSLog(@"Outside");

    UIAlertController *alert=[UIAlertController alertControllerWithTitle:@"Monitoring" message:@"Outside" preferredStyle:UIAlertControllerStyleAlert];

    UIAlertAction *action=[UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
}];

    [alert addAction:action];

    [self presentViewController:alert animated:YES completion:nil];

}

1 ответ

Вы должны удалить строку [_manager startUpdatingLocation], я думаю, вам не нужно вызывать это, потому что вы хотите только мониторинг региона.

Другие вопросы по тегам