ジオフェンシング アプリを開発していますが、機能しません。
didStartMonitoringForRegion デリゲート メソッドを取得しています。通知と警告メッセージは、didStartMonitoringForRegion で正常に機能しています。しかし、didEnterRegion と didExitRegion は呼び出されるべきときに呼び出されません。
半径を200mに設定し、300m以上歩き、数分待ちました。しかし、didExitRegion は機能せず、実際の場所を返している間、didEnterRegion も呼び出されません。
コードを以下に示します。
- (void)viewDidLoad {
[super viewDidLoad];
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager requestAlwaysAuthorization];
CLLocationCoordinate2D centers = CLLocationCoordinate2DMake(13.015624, 80.200276);
CLRegion *geoLoc = [[CLCircularRegion alloc]initWithCenter:centers radius:200.0
identifier:@"ident"];
geoLoc.notifyOnExit = TRUE;
geoLoc.notifyOnEntry = TRUE;
[locationManager startUpdatingLocation];
[locationManager startMonitoringForRegion:geoLoc desiredAccuracy:kCLLocationAccuracyBest];
}
- (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Location Message"
message:@"exit region"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[self testNotifications];
}
-(void) testNotifications {
// function for the sample push notification
}
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region {
[self testNotifications];
}
- (void)locationManager:(CLLocationManager *)manager
didStartMonitoringForRegion:(CLRegion *)region {
[self testNotifications];
// alert code
NSLog(@"Started Monitoring region:%f", region.center.latitude);
// the region and the given value is getting printed
}
リージョンの外側と内側から didEnterRegion と didExitRegion を呼び出し、通知/ポップアップを表示する方法についての提案は大歓迎です!