I'm developing a geofencing app but it doesn't work.

I'm getting the didStartMonitoringForRegion delegate method. The notification and the alert messages are working fine in didStartMonitoringForRegion. But, didEnterRegion and didExitRegion don't get called when they should.

I have set the radius as 200m and walked more than 300m and waited for a few minutes. But the didExitRegion hasn't worked and while returning the actual location, didEnterRegion is also not called.

The code has given below.

- (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

}

Any suggestions on how to call the didEnterRegion and didExitRegion from outside and inside the region and show the notification/popup would be much appreciated!

0

There are 0 best solutions below