I am trying to write an app in iOS for the iPhone 4 using significant location change that fires a local notification each time the location delegate receives a location update. My code is posted below. I resign the app and close it out of the background. 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, receiving a text, etc. Then the notification is fired. What do I need to do in order for location updates to register even when the device is asleep? Thanks in advance.
SigLoc.h
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
@interface SigLocViewController : UIViewController <CLLocationManagerDelegate> {
CLLocationManager *locationManager;
}
@property (nonatomic, retain) CLLocationManager *locationManager;
@end
SigLoc.m
#import "SigLocViewController.h"
@implementation SigLocViewController
@synthesize locationManager;
- (void)viewDidLoad {
self.locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startMonitoringSignificantLocationChanges];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
UIApplication *app = [UIApplication sharedApplication];
UILocalNotification *alarm = [[[NSClassFromString(@"UILocalNotification") alloc] init] autorelease];
if (alarm) {
alarm.fireDate = nil;
alarm.repeatInterval = 0;
alarm.alertBody = @"Location Update";
alarm.soundName = UILocalNotificationDefaultSoundName;
alarm.hasAction = NO;
[app presentLocalNotificationNow:alarm];
}
}