Я пишу прототип типа для мониторинга региона. Ниже мой набор кодаdidEnterRegion in iOS 8 - Мониторинг региона
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[self.locationManager requestWhenInUseAuthorization];//commented for iOS 7
Вот как я создаю locationManager
В 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>
Тогда
-(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;
}
Я проверки этих условий
-(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;
}
Этот набор коды отлично работает на прошивке 7.
Но когда я бег то же самого в прошивке 8, когда я начинаю мониторинг, метод делегата didStartMonitoringForRegion
становится называется. Но didEnterRegion
никогда не вызывается, когда я вхожу в регион.
Есть ли что-нибудь, что я должен уделить особое внимание iOS 8?
Возможный дубликат [Geofencing сделалEnterRegion, didExitRegion функция не звонит в iphone 5S iOS8.1] (http://stackoverflow.com/questions/27521220/geofencing-didenterregion-didexitregion-function-not-calling-in-iphone- 5s-ios8-1) – Vizllx