Using some details from @apptality I was able to get this working with Darwin Notifications. This answer explains how to get the notifications working. I used the following code to do this:
in AppDelegate's didFinishLaunchingWithOptions
method place the following code :
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), //center
(void*)self, // observer (can be NULL)
lockStateChanged, // callback
CFSTR("com.apple.springboard.lockcomplete"), // event name
NULL, // object
CFNotificationSuspensionBehaviorDeliverImmediately);
Then use this method to handle the notifications:
static void lockStateChanged(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) {
NSLog(@"event received!");
if (observer != NULL) {
AppDelegate *this = (__bridge AppDelegate*)observer;
NSString* notifyName = (__bridge NSString*)name;
if ([notifyName isEqualToString:@"com.apple.springboard.lockcomplete"]) {
[this localNotificationSetup];
}
}
}
where localNotificationSetup
is where you register your notifications for delivery. Be careful as this is a c-based method so much of your objective-c code needs changing. You can then use this method to handle actions on the notification:
-(void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(UILocalNotification *)notification withResponseInfo:(NSDictionary *)responseInfo completionHandler:(void (^)())completionHandler
To actually accomplish anything useful you may need to load data from nsuserdefaults in this method if your app goes to sleep.