【问题标题】:Region based local notification基于区域的本地通知
【发布时间】:2012-04-19 04:59:49
【问题描述】:

我目前正在使用“区域”示例代码: https://developer.apple.com/library/ios/#samplecode/Regions/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010726-Intro-DontLinkElementID_2

我想更进一步,并在用户退出该区域时生成或触发通知(可以用于进入和退出,我不介意,对于初始实现来说最简单的方法) .

我一直在查看 CLLocation 类参考、位置感知编程指南和本地和推送通知编程指南。而且我正遭受信息过载的困扰。

非常感谢:)

编辑:我想我可能有一个解决问题的想法: 在 RegionsViewController 实现文件中有这样的:

- (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region        {
    NSString *event = [NSString stringWithFormat:@"didExitRegion %@ at %@", region.identifier, [NSDate date]];

    [self updateWithEvent:event];
}

因为我想在用户退出指定区域边界时实现本地通知,所以我输入了这个:

- (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region {
    NSString *event = [NSString stringWithFormat:@"didExitRegion %@ at %@", region.identifier, [NSDate date]];
    [self updateWithEvent:event];
    //implement local notification: 
    UIApplication *app                = [UIApplication sharedApplication];
    UILocalNotification *notification = [[UILocalNotification alloc] init];
    [[UIApplication sharedApplication] cancelAllLocalNotifications];

    if (notification == nil)
        return;

    notification.alertBody = [NSString stringWithFormat:@"Did You Lock Your House?"];
    notification.alertAction = @"Lock House";
    notification.soundName = UILocalNotificationDefaultSoundName; 
    notification.applicationIconBadgeNumber = 1;
    [app presentLocalNotificationNow:notification];

    [notification release];
}

有人可以告诉我这是否正确,或者是否有任何建议? (为糟糕的格式道歉)

【问题讨论】:

    标签: geolocation geocoding geofencing


    【解决方案1】:

    你是对的,没有比从 locationManager:didExitRegion 发出本地通知更好的方法了: 此外,即使您的应用在后台运行或关闭,这也能正常工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-04-11
      • 1970-01-01
      • 1970-01-01
      • 2015-05-11
      • 2016-12-29
      • 2023-03-05
      • 1970-01-01
      相关资源
      最近更新 更多