我有一个关于在后台模式下运行时由于位置区域事件而显示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文件中,我将'Required background modes - Item 0‘设置为'App register for location update’,将'Required device capabilities Item 0‘设置为'location-services’,将'Item 1‘设置为'GPS’。
任何帮助都非常感谢!
发布于 2011-10-10 16:57:09
当你的应用程序处于后台时,UIAlertView将无法工作。当你的应用程序在后台运行时,你应该使用UILocalNotifications。
还需要注意的是,在达到所需精度的情况下,iPhone电池的电量将很快耗尽。在后台运行时,有一个特殊的CCLocationManager设置,只有在发生重大更改时才会调用此设置,这可能不会为您累积足够的值。
https://stackoverflow.com/questions/7710392
复制相似问题