首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >iPhone中的地理栅栏

iPhone中的地理栅栏
EN

Stack Overflow用户
提问于 2014-12-17 15:36:49
回答 2查看 191关注 0票数 0

我写了一个地理围栏应用程序,当它在前台和后台运行时工作得很好。如何使该应用程序工作,并发送有关地理围栏的通知,即使该应用程序被杀死?

EN

回答 2

Stack Overflow用户

发布于 2014-12-17 15:48:06

当应用程序被杀死时,iOS仍然会监控地理栅栏。如果您进入或退出一个,您的AppDelegate application:didFinishLaunchingWithOptions:将被调用。然后,您可以使用启动选项检测这是否是位置触发器:

代码语言:javascript
复制
 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.
    }
票数 0
EN

Stack Overflow用户

发布于 2016-02-19 14:26:20

您也可以在开始监控您的区域时创建通知:

代码语言:javascript
复制
    [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

  • when中时,应用程序在background

  • when中时,应用程序是

这三种情况的通知回调都是在UIApplicationDelegate方法- application:didReceiveLocalNotification:中接收的

代码语言:javascript
复制
-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
    //Do whatever you want after you receive the notification
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27520412

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档