- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
ne fonctionne que si la UIView correspondant à la classe qui implémente CLLocationManagerDelegate est active.
Si je change la vue, cela ne déclenchera pas didEnterRegion. Quelqu'un peut-il m'aider ?
Mon code ressemble à ceci
- (void)enableRegionMonitoring {
locationManager = [[CLLocationManager alloc] init];
[locationManager setDelegate:self];
CLLocationCoordinate2D myMonLocation = CLLocationCoordinate2DMake(10.766699790955, 76.650101525879);
CLRegion *myRegion = [[CLRegion alloc]
initCircularRegionWithCenter:myMonLocation
radius:100
identifier:@"MyLoc"];
//NSLog(@"reg=%@",myRegion);
// Start monitoring for our CLRegion using best accuracy
[locationManager startMonitoringForRegion:myRegion
desiredAccuracy:kCLLocationAccuracyBest];
}
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region {
NSLog(@"Entered Region");
NSDate *nowx=[NSDate date];
UILocalNotification *localNotification=[[UILocalNotification alloc]init];
if (!localNotification)
return;
NSDictionary *data = [NSDictionary dictionaryWithObject:@"qw" forKey:@"mykey"];
[localNotification setUserInfo:data];
[localNotification setFireDate:nowx];
[localNotification setTimeZone:[NSTimeZone defaultTimeZone]];
NSMutableString *message=[[NSMutableString alloc]init];
message = @"Local Not Triggered By didEnterRegion";
[localNotification setAlertBody:[nowx description]];
[localNotification setAlertAction:@"Open App"];
[localNotification setHasAction:YES];
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
}