【问题标题】:How to use Geo-fencing methods in background如何在后台使用地理围栏方法
【发布时间】:2012-09-09 11:28:59
【问题描述】:

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

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

}

【问题讨论】:

    标签: ios core-location geofencing


    【解决方案1】:

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

    Geolocation with local notification like reminder

    剪辑>

    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 中处理通知

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-11-30
      • 1970-01-01
      • 1970-01-01
      • 2016-11-10
      • 1970-01-01
      • 2016-09-30
      • 2020-10-18
      相关资源
      最近更新 更多