3

I am trying to write an app in iOS for the iPhone 4 using startMonitoringForRegion that fires a local notification each time the location delegate receives a location update.

As long as the phone is awake (the screen is lit up), the application works well, firing the notifications, but when I put the phone to sleep (the screen is black), I no longer receive notifications until I wake the phone up by pressing the home button

I'm tried to add "Required background modes" - "App registers for location updates" key in info.plist but it's make no sense...

CLLocationManager delegate is setted up as AppDelegate.

What do I need to do in order for location updates to register even when the device is asleep? Thanks in advance.

4

1 回答 1

0

可能是应用程序关闭后 CLLocationManager 实例已被释放。

对我来说,我会创建一个带有 CLLocationManager 属性的单例位置管理器,并将委托设置为单例。之后,我会调用该方法startMonitoringSignificantLocationChanges以确保应用程序接收到位置更新。即使应用程序被杀死,它也会起作用。

对于应用程序被终止的情况,我需要在应用程序委托didFinishLaunchingWithOptions方法中实例化位置管理器单例:

if ([launchOptions objectForKey:UIApplicationLaunchOptionsLocationKey]) {
    //instantiate the singleton here
    NSArray *regions = [[[[LocationManager sharedManager] locationManager] monitoredRegions] allObjects];
}

我在这里更详细地解释了使用重大位置更改和标准位置服务之间的区别:应用程序未运行时基于位置的推送通知?

于 2013-05-18T09:21:48.547 回答