Region monitoring for current location of iOS 7

I want to create an application that will give me a message to enter and exit for the current position with a radius of 10 meters. Here is my code:

-(void)startLocationServices
{
    if (self.locationManager == nil)
    {
        self.locationManager = [CLLocationManager new];
    }
    [self.locationManager setDelegate:self];
    [self.locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
    [self.locationManager setDistanceFilter:kCLDistanceFilterNone];
    [self.locationManager startUpdatingLocation];
}

-(void)stopLocationServices
{
    [self.locationManager stopUpdatingLocation];
    [self.locationManager setDelegate:nil];

    //self.locationUpdateTextView.text = @"Location Service stop";
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self startLocationServices];
}

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
    self.locationUpdateTextView.text = [@"New Location: \n\n" stringByAppendingFormat:@"%@ \n \nCurrent Position\nLatitude: %f \nLongitude: %f", [locations lastObject], self.locationManager.location.coordinate.latitude, self.locationManager.location.coordinate.longitude];

    CLLocationCoordinate2D center = CLLocationCoordinate2DMake(locationManager.location.coordinate.latitude, locationManager.location.coordinate.longitude);

    CLCircularRegion *region = [[CLCircularRegion alloc] initWithCenter:center radius:10.0 identifier:@"Test"];

    [self.locationManager startMonitoringForRegion:region];
    [self stopLocationServices];
}

- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
{
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Status" message:@"You Enter the region" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];

    [alertView show];
}

- (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region
{
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Status" message:@"You Exit the region" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];

    [alertView show];
}

- (void) locationManager:(CLLocationManager *)manager monitoringDidFailForRegion:(CLRegion *)region withError:(NSError *)error
{
    self.availabilityTextView.text = [@"\nError:" stringByAppendingFormat:@"%@", error];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

I call [self stopLocationServices];the didUpdateLocationsmethod to capture the current position of the user, set the radius, and then stop. When I run the application and move 10 meters, it does not give any warning messages, although I am crossing a 10-meter radius. Rather, I get this randomly, especially when I restart the application after crossing a 10 meter radius. I know the problem with the cell in this case, but I'm not sure if my thinking works exactly in this scenario. If someone understands my problem and knows a solution, please share it with me.

+3

All Articles