我正在尝试制作一个应用程序,当他进入某个区域时通知用户。我在应用程序处于活动状态时做到了,但我不知道如何在后台进行。任何人都可以帮助我吗?
这是我使用的代码:
self.locationManager = [[[CLLocationManager alloc] init] autorelease];
locationManager.delegate = self;
locationManager.desiredAccuracy=kCLLocationAccuracyBestForNavigation;
[locationManager startUpdatingLocation];
if ([CLLocationManager regionMonitoringAvailable] && [CLLocationManager regionMonitoringEnabled])
{
loc = CLLocationCoordinate2DMake(30.794686, 31.012309);
alslamMosque =[[CLRegion alloc]initCircularRegionWithCenter:loc radius:10 identifier:@"alslam"];
CLLocationAccuracy acc = kCLLocationAccuracyNearestTenMeters;
[locationManager startMonitoringForRegion:alslamMosque desiredAccuracy:acc];
[locationManager startMonitoringSignificantLocationChanges];
}
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
{
UIAlertView *alr=[[UIAlertView alloc] initWithTitle:[NSString stringWithFormat: @"you've enterd region and you are %f meters from",dd]
message:region.identifier delegate:nil cancelButtonTitle:nil otherButtonTitles:@"Ok",nil];
[alr show];
[alr release];
NSLog(@"enter region");
}