我是基于位置的应用程序的新手。 我的要求是,当用户到达所选区域时,设备必须显示基于位置的通知。 我完美地实现了。此应用程序也在后台运行。 现在我的新要求是,即使在终止应用程序后,设备也必须显示基于位置的通知。 [我看到几个 iPhone 应用程序使用此功能。这些应用程序是“提醒”和“定位器”]。
能否请您检查我的实现步骤如下。
- 启动应用程序。
- 选择位置提醒按钮。
调用了以下 CLLocationManager API 来监控我的区域。
[locationManager startMonitoringForRegion:@"MyRegion"desiredAccuracy:kCLLocationAccuracyBest]; [locationManager startMonitoringSignificantLocationChanges];
退出应用[在后台运行]。
- 我正在正确接收基于位置的警报通知。
这里是新要求。
- 启动应用程序。
- 选择位置提醒按钮。
调用了以下 CLLocationManager API 来监控我的区域。
[locationManager startMonitoringForRegion:@"MyRegion"desiredAccuracy:kCLLocationAccuracyBest]; [locationManager startMonitoringSignificantLocationChanges];
终止应用程序。 [现在应用程序不在后台运行]
应用应在用户到达位置时显示基于位置的通知。
我如何实现这个逻辑?
最佳答案
嗨, friend 们,我找到了这个问题的解决方案。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
id locationValue = [launchOptions objectForKey:UIApplicationLaunchOptionsLocationKey];
if (locationValue)
{
[self initLocationMonitoring]; // this will invoke CLLocationManager
}
return YES;
}
关于iphone - 基于位置的通知不会在挂起模式下调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9581509/