我写了一个地理围栏应用程序,当它在前台和后台运行时工作得很好。如何使该应用程序工作,并发送有关地理围栏的通知,即使该应用程序被杀死?
发布于 2014-12-17 15:48:06
当应用程序被杀死时,iOS仍然会监控地理栅栏。如果您进入或退出一个,您的AppDelegate application:didFinishLaunchingWithOptions:将被调用。然后,您可以使用启动选项检测这是否是位置触发器:
if (launchOptions[UIApplicationLaunchOptionsLocationKey])
{
//Re-Setup your location manager and take appropriate action. The locationManager:didEnterRegion: locationManager:didExitRegion delegate of the new location manager will be triggered.
}发布于 2016-02-19 14:26:20
您也可以在开始监控您的区域时创建通知:
[self.locationManager startMonitoringForRegion:region];
UILocalNotification *regionNotification = [UILocalNotification new];
NSString *notificationString = [NSString stringWithFormat:@"You are approaching near region%@",region.identifier];
regionNotification.alertBody = notificationString;
regionNotification.alertAction = @"Show me the region details.";
regionNotification.region = region;
regionNotification.regionTriggersOnce = NO;
regionNotification.userInfo = [NSDictionary dictionaryWithObject:region.identifier forKey:@"regionIdentifier"];
[[UIApplication sharedApplication]scheduleLocalNotification:regionNotification];此通知适用于所有3种情况:
当应用程序在foreground
这三种情况的通知回调都是在UIApplicationDelegate方法- application:didReceiveLocalNotification:中接收的
-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
//Do whatever you want after you receive the notification
}https://stackoverflow.com/questions/27520412
复制相似问题