Reputation: 1466
i've an application where i need to use StartMonitoringForRegion. when i put the following code in the application didFinishLaunchingWithOptions it works.
[loc startUpdatingLocation];
CLLocationCoordinate2D coord = CLLocationCoordinate2DMake(21.456372,39.287972);
CLRegion* region = [[CLRegion alloc] initCircularRegionWithCenter:coord radius:200 identifier:@"C"];
[self.locationManager startMonitoringForRegion:region desiredAccuracy:50];
but when i use the same code in another view, it does not work!! i tried to execute the code on the main thread using the following code:
if (![NSThread isMainThread])
{
[self performSelectorOnMainThread:@selector(MonitorRegion:) withObject:pr waitUntilDone:NO];
return;
}
but it still does not work!
why would the code work in the didFinishLaunchingWithOptions and not in the other view!
is there any cases where the monitor for region might not work?
Upvotes: 1
Views: 795
Reputation: 1466
after searching and different trials i figured out how to solve it.
simply that view has to be visible and running all the time in order for the didEnterRegion and didExitRegion to work.
i moved everything to the appDelegate and now it's working.
Upvotes: 2