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 に答える