【问题标题】:Display iPhone alert from background mode when monitoring region boundary crossing监视区域边界交叉时从后台模式显示 iPhone 警报
【发布时间】:2011-10-10 08:47:26
【问题描述】:

由于位置区域事件,我有一个关于在后台模式下运行时显示 UIAlertView 的问题。我在此处对类似问题进行了广泛的搜索,并下载了 Apple Breadcrumb 示例,但它并未尝试显示警报。

我的应用在进入后台模式之前切换到区域监控:

[self.locMan startMonitoringForRegion:targetRegion desiredAccuracy:100];

然后我监控区域进入和退出如下:

-(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 文件中,我已将“所需的后台模式 - 项目 0”设置为“应用程序注册以进行位置更新”,将“所需的设备功能 - 项目 0”设置为“位置服务”,将“项目 1”设置为“全球定位系统'。

非常感谢任何帮助!

【问题讨论】:

    标签: iphone objective-c location uialertview background-process


    【解决方案1】:

    UIAlertView 在您的应用程序处于后台时将不起作用。 当您的应用在后台运行时,您应该使用UILocalNotifications

    另外请注意,如果达到所需的精度,您将很快耗尽 iPhone 电池。 CCLocationManager 在后台运行时有一个特殊设置,它只会在重大更改时调用,这可能对您来说不够。

    【讨论】:

    • 啊哈!我将研究使用 UILocalNotifications。准确地说,这只是一个开发设置——不幸的是,我太清楚我手机的电池寿命了!非常感谢您的快速回复,非常感谢。
    • 嗨,我现在有一个工作版本:-) 我正在使用区域监控,这看起来很古怪,但是当它触发时,我确实会立即看到通知。非常感谢。
    猜你喜欢
    • 2011-09-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-28
    相关资源
    最近更新 更多