3

我正在尝试制作一个应用程序,当他进入某个区域时通知用户。我在应用程序处于活动状态时做到了,但我不知道如何在后台进行。任何人都可以帮助我吗?
这是我使用的代码:

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");

}
4

1 回答 1

1

这是您正在寻找的堆栈上的直接链接:

带有本地通知(如提醒)的地理位置

剪辑>

UILocalNotification *notification = [[UILocalNotification alloc] init]; 
notification.fireDate = [NSDate date]; 
NSTimeZone* timezone = [NSTimeZone defaultTimeZone]; 
notification.timeZone = timezone; 
notification.alertBody = @"Notification message"; 
notification.alertAction = @"Show"; 
notification.soundName = UILocalNotificationDefaultSoundName; 
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
[notification release]; // release if not using ARC

之后继续并确保您在 App Delegate 中处理通知

于 2014-04-14T22:59:39.260 回答