I am writing a prototype type for Region monitoring. Below is my set of code
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[self.locationManager requestWhenInUseAuthorization];//commented for iOS 7
Thats how I create locationManager
In plist,
<key>NSLocationAlwaysUsageDescription</key>
<string>Location is required to find out where you are</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Location is required to find out where you are</string>
Then
-(BOOL) checkLocationManager
{
if(![CLLocationManager locationServicesEnabled])
{
[self showMessage:@"You need to enable Location Services"];
return FALSE;
}
if(![CLLocationManager isMonitoringAvailableForClass:[CLRegion class]])
{
[self showMessage:@"Region monitoring is not available for this Class"];
return FALSE;
}
if([CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied ||
[CLLocationManager authorizationStatus] == kCLAuthorizationStatusRestricted )
{
[self showMessage:@"You need to authorize Location Services for the APP"];
return FALSE;
}
return TRUE;
}
I am checking for those conditions
-(void) addGeofence:(NSDictionary*) dict
{
CLRegion * region = [self dictToRegion:dict];
[locationManager startMonitoringForRegion:region];
}
- (CLRegion*)dictToRegion:(NSDictionary*)dictionary
{
NSString *identifier = [dictionary valueForKey:@"identifier"];
CLLocationDegrees latitude = [[dictionary valueForKey:@"latitude"] doubleValue];
CLLocationDegrees longitude =[[dictionary valueForKey:@"longitude"] doubleValue];
CLLocationCoordinate2D centerCoordinate = CLLocationCoordinate2DMake(latitude, longitude);
CLLocationDistance regionRadius = [[dictionary valueForKey:@"radius"] doubleValue];
if(regionRadius > locationManager.maximumRegionMonitoringDistance)
{
regionRadius = locationManager.maximumRegionMonitoringDistance;
}
NSString *version = [[UIDevice currentDevice] systemVersion];
CLRegion * region =nil;
if([version floatValue] >= 7.0f) //for iOS7
{
region = [[CLCircularRegion alloc] initWithCenter:centerCoordinate
radius:regionRadius
identifier:identifier];
}
else // iOS 7 below
{
region = [[CLRegion alloc] initCircularRegionWithCenter:centerCoordinate
radius:regionRadius
identifier:identifier];
}
return region;
}
This set of code works perfectly on iOS 7.
But when I run the same in iOS 8, when I start monitoring, the delegate method didStartMonitoringForRegion
is getting called. But didEnterRegion
is never called when I enter the region.
Is there anything that I should take extra care for iOS 8?