首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >监控区域越界时,后台显示iPhone告警

监控区域越界时,后台显示iPhone告警
EN

Stack Overflow用户
提问于 2011-10-10 16:47:26
回答 1查看 1.5K关注 0票数 1

我有一个关于在后台模式下运行时由于位置区域事件而显示UIAlertView的问题。我已经在这里广泛地收集了类似的问题,并下载了Apple Breadcrumb示例,但它不会尝试显示警报。

我的应用程序在进入后台模式之前切换到监控区域,代码如下:

代码语言:javascript
复制
[self.locMan startMonitoringForRegion:targetRegion desiredAccuracy:100];

然后,我监视区域的入口和出口,如下所示:

代码语言:javascript
复制
-(void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region
{
NSLog(@"Exited region");

UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Region Boundary Crossed!" 
                                                    message:@"Exited region"
                                                   delegate:self 
                                          cancelButtonTitle:@"Cancel" 
                                          otherButtonTitles:@"Show",nil ]; 

[alertView show];
[alertView release];
}


-(void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region 
{
NSLog(@"Entered region"); 

UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Region Boundary Crossed!" 
                                                    message:@"Entered region"
                                                   delegate:self 
                                          cancelButtonTitle:@"Cancel" 
                                          otherButtonTitles:@"Show",nil ]; 
[alertView show];
[alertView release];
}

我已经使用模拟器运行了它,以确认它正确地切换到区域监控。然而,在iPhone上,当在后台模式下运行时,我无法看到警报,但当重新激活应用程序时,会显示所需的警报,似乎在排队等待。

在我的info.plist文件中,我将'Required background modes - Item 0‘设置为'App register for location update’,将'Required device capabilities Item 0‘设置为'location-services’,将'Item 1‘设置为'GPS’。

任何帮助都非常感谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-10-10 16:57:09

当你的应用程序处于后台时,UIAlertView将无法工作。当你的应用程序在后台运行时,你应该使用UILocalNotifications

还需要注意的是,在达到所需精度的情况下,iPhone电池的电量将很快耗尽。在后台运行时,有一个特殊的CCLocationManager设置,只有在发生重大更改时才会调用此设置,这可能不会为您累积足够的值。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7710392

复制
相关文章

相似问题

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