Я работаю над демо для Goefencing.Методы делегирования CLLocationManager didEnterRegion, didExitRegion и didDetermineState не вызываются на iOS 8.4 (устройство)
Вот мой код,
- (void) registerRegionForMonitoring {
if (self.locationManager == nil) {
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
self.locationManager.distanceFilter = kCLDistanceFilterNone;
if ([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
[self.locationManager requestAlwaysAuthorization];
}
[self.locationManager startUpdatingLocation];
}
if(![CLLocationManager isMonitoringAvailableForClass:[CLCircularRegion class]]) {
[Utilities showAlertWithTitle:@"Geofence" andMessage:@"This app requires region monitoring features which are unavailable on this device."];
return;
}
for(NSDictionary *dictionary in geofences) {
NSString *geofenceId = [NSString stringWithFormat:@"%@", [dictionary valueForKey:@"geofence_id"]];
CLLocationDegrees latitude = [[dictionary valueForKey:@"latitude"] doubleValue];
CLLocationDegrees longitude =[[dictionary valueForKey:@"longitude"] doubleValue];
CLLocationCoordinate2D centerCoordinate = CLLocationCoordinate2DMake(latitude, longitude);
CLLocationDistance regionRadius = [[dictionary valueForKey:@"radius"] doubleValue];
CLRegion *geofenceRegion = [[CLCircularRegion alloc] initWithCenter:centerCoordinate radius:regionRadius identifier:geofenceId];
[self.locationManager startMonitoringForRegion:geofenceRegion];
}
}
Вот делегат метода
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
CLLocation *latestLocation = [locations lastObject];
self.currentLocation = latestLocation;
}
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region {
[Utilities showAlertWithTitle:@"Geofence" andMessage:[NSString stringWithFormat:@"You are in region with identifire %@", region.identifire]];
}
- (void)locationManager:(CLLocationManager *)manager didStartMonitoringForRegion:(CLRegion *)region {
[self.locationManager requestStateForRegion:region];
}
- (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region {
[Utilities showAlertWithTitle:@"Geofence" andMessage:[NSString stringWithFormat:@"You are out of region with identifire %@", region.identifire]];
}
- (void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region {
if (state == CLRegionStateInside) {
// if user already in the region, when monitoring is started
[Utilities showAlertWithTitle:@"Geofence" andMessage:[NSString stringWithFormat:@"You are in region with identifire %@", region.identifire]];
}
}
Я также добавил ключ "NSLocationAlwaysUsageDescription"
в plist
файле для прошивки 8+
Также ниже добавлены режимы фона:
App регистрирует наличие обновлений местоположения
App акций данных с использованием CoreBluetooth
App общается с помощью CoreBluetooth
App содержание загрузки в ответ на уведомления толчка
Все работы отлично работает с iOS 7, а также работает в iOS-симуляторе для iOS 8.4
Он не работает на устройстве (iOS 8.4, iPad и iPod)
Я проверил с Wi-Fi.
Я также включил «Общие» -> «Фон App Refresh» в настройках
Я не знаю, что мне не хватает?
Все предложения приветствуются. Заранее спасибо.
Можете ли вы объяснить, как именно вы тестируете приложение при работе на устройстве? Является ли это работой или местом, смоделированным с помощью Xcode (подсказка: результаты могут быть разными) –
@AlexPavlov: спасибо за немедленный ответ. Что я сделал, я добавил текущие координаты местоположения с радиусом 1000 м для создания региона. Затем добавил этот регион для мониторинга. Поэтому он должен вызвать метод defineState. Но это не так. Хотя то же самое работает на моем симуляторе iOS 8.4 –