Я занимаюсь разработкой приложения для геозон, но оно не работает.
Я получаю метод делегата didStartMonitoringForRegion. Уведомление и предупреждающие сообщения работают нормально в didStartMonitoringForRegion. Но didEnterRegion и didExitRegion не вызывают, когда они должны.
Я установил радиус на 200 м, прошел более 300 м и ждал несколько минут. Но didExitRegion не работает, и при возврате фактического местоположения didEnterRegion также не вызывается.
Код приведен ниже.
- (void)viewDidLoad {
[super viewDidLoad];
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager requestAlwaysAuthorization];
CLLocationCoordinate2D centers = CLLocationCoordinate2DMake(13.015624, 80.200276);
CLRegion *geoLoc = [[CLCircularRegion alloc]initWithCenter:centers radius:200.0
identifier:@"ident"];
geoLoc.notifyOnExit = TRUE;
geoLoc.notifyOnEntry = TRUE;
[locationManager startUpdatingLocation];
[locationManager startMonitoringForRegion:geoLoc desiredAccuracy:kCLLocationAccuracyBest];
}
- (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Location Message"
message:@"exit region"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[self testNotifications];
}
-(void) testNotifications {
// function for the sample push notification
}
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region {
[self testNotifications];
}
- (void)locationManager:(CLLocationManager *)manager
didStartMonitoringForRegion:(CLRegion *)region {
[self testNotifications];
// alert code
NSLog(@"Started Monitoring region:%f", region.center.latitude);
// the region and the given value is getting printed
}
Любые предложения о том, как вызывать didEnterRegion и didExitRegion извне и внутри региона и показывать уведомление / всплывающее окно, будут высоко оценены!