监控区域边界穿越时从后台模式显示 iPhone 警报
我有一个关于在后台模式下运行时由于位置区域事件而显示 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”设置为“GPS”。
非常感谢任何帮助!
I have a question about displaying a UIAlertView when running in background mode as a result of a location region event. I have done an extensive trawl of similar questions on here and have downloaded the Apple Breadcrumb example but it doesn't attempt to display alerts.
My app switches to monitoring for regions just before it enters background mode with this line:
[self.locMan startMonitoringForRegion:targetRegion desiredAccuracy:100];
I then monitor for region entry and exit as follows:
-(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];
}
I have run this using the simulator to confirm that it correctly switches to region monitoring. However, on the iPhone I have not been able to see an alert when running in the background mode but desired alerts are displayed when reactivating the app, seemingly queued up and waiting.
In my info.plist file I have set 'Required background modes - Item 0' to 'App registers for location updates' and 'Required device capabilities - Item 0' to 'location-services' and 'Item 1' to 'GPS'.
Any help much appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您的应用程序处于后台时,
UIAlertView
将不起作用。当您的应用程序在后台运行时,您应该使用
UILocalNotifications
。另请注意,如果达到所需的准确度,iPhone 电池的电量会很快耗尽。
当在后台运行时,CCLocationManager 有一个特殊的设置,只有在重大更改时才会调用该设置,这对您来说可能不够。
UIAlertView
will not work when your app is backgrounded.You should use
UILocalNotifications
when you app is running in the background.Also be aware that with the desired accuracy you will drain the iPhone battery really quick.
There is a special setting for CCLocationManager when running in the background, this will only get called on major change, which might not be accrued enough for you.