I'm trying to write an app that notifies the user whenever he enters a specific region (I have 20 regions that being updates base on the user's current location).
I added a breakpoint on -locationManager: didEnterRegion:
but it's never been called although the user's current location is inside the region (using the simulator).
It will really help me if someone will be able to help me detect the problem.
Thanks!
My code:
remindersViewController.m:
-(void)startMonitoringClosestStores
{
[self stopMonitoringStores];
if (![CLLocationManager isMonitoringAvailableForClass:[CLCircularRegion class]]) {
NSLog(@"Monitoring is not available for CLCircularRegion class");
}
for (Store *currentStore in self.twentyClosestStores) {
CLCircularRegion *region=[currentStore createCircularRegion];
[self.locationManager startMonitoringForRegion:region];
}
}
-(void)stopMonitoringStores
{
for (Store *currentStore in self.twentyClosestStores) {
CLCircularRegion *region=[currentStore createCircularRegion];
[self.locationManager stopMonitoringForRegion:region];
}
}
-(void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
{
NSLog (@"Enetred"); //Never called
}
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations
{
self.userLocation=[locations lastObject];
[self sortClosestStores];
}
Store.m:
-(CLCircularRegion*)createCircularRegion
{
CLCircularRegion *region=[[CLCircularRegion alloc] initWithCenter:self.geoPoint radius:1000 identifier:self.identifier];
region.notifyOnEntry=YES;
return region;
}
AppDelegate.m:
-(void)handleRegionEvent:(CLRegion*)region
{
NSLog(@"Geofence triggered");
}
-(void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
{
NSLog(@"Entered");
}