Geolocation 基于区域的本地通知
我目前正在使用“区域”示例代码: tml#//apple_ref/doc/uid/DTS40010726-Intro-DontLinkElementID_2 我想更进一步,在用户退出该区域时生成或触发一个通知(可以是enter和exit,我不介意,任何对于初始实现来说最简单的) 我一直在看CLLocation类参考、位置感知编程指南以及本地和推送通知编程指南。我正遭受信息过载的痛苦 非常感谢:) 编辑:我想我可能有一个解决问题的办法: 在RegionsViewController实现文件中有以下内容:Geolocation 基于区域的本地通知,geolocation,geocoding,geofencing,Geolocation,Geocoding,Geofencing,我目前正在使用“区域”示例代码: tml#//apple_ref/doc/uid/DTS40010726-Intro-DontLinkElementID_2 我想更进一步,在用户退出该区域时生成或触发一个通知(可以是enter和exit,我不介意,任何对于初始实现来说最简单的) 我一直在看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];
}
有没有人能告诉我这是否正确,或者是否有任何建议?(对格式错误深表歉意)没错,没有比从locationManager:DidexitreRegion: 此外,即使你的应用程序在后台运行或关闭,这也会起作用