3

FIXED — Ok, found what it was, there was an errant [[UIApplication sharedApplication] cancelAllLocalNotifications]; being fired when I wasn't expecting it.

Well there's your problem.

Thanks for the help everyone, sorry to have it turn out to just be dumb coder syndrome.

I've built out my local notification like so:

- (void)scheduleNotification {
    [[UIApplication sharedApplication] cancelAllLocalNotifications];
    Class cls = NSClassFromString(@"UILocalNotification");
    if (cls != nil) {
        UILocalNotification *notif = [[cls alloc] init];
        NSLog(@"%@", [NSDate date]);
        notif.fireDate = [NSDate dateWithTimeIntervalSinceNow:10];

        notif.alertBody = NSLocalizedString(@"Hello.", nil);

        [[UIApplication sharedApplication] scheduleLocalNotification:notif];
        NSLog(@"Notification scheduled at %@", notif.fireDate);
        [notif release];
    }
}

As expected my debug log outputs the correct fireDate 10 seconds in the future. If I don't leave my app I get a successful application:didReceiveLocalNotification: callback.

The hiccup here is if I push the button to schedule this notification and hit the home button to put it in the background. If I do this, the notification never fires and I never get an alert view from the OS.

Did I miss something obvious here? I've looked up and down here and the Apple docs and feel I've missed something obvious.

Any help would be greatly appreciated. Thanks.

Jay Baird
  • 120
  • 1
  • 6
  • Please add your solution as an answer, so this question isn't listed on the Unanswered Questions list any longer, and might help someone else in the future find the solution to their problem. – sarnold Jul 04 '11 at 09:26

3 Answers3

1

See the example in Apple's docs: http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/IPhoneOSClientImp/IPhoneOSClientImp.html#//apple_ref/doc/uid/TP40008194-CH103-SW1

Could it be that not setting timeZone to [NSTimeZone defaultTimeZone] is causing the problem? GMT is assumed if timeZone isn't set (nil default).

hanleyp
  • 811
  • 9
  • 5
  • I want the universal time version (no timeZone) since I want the notification to fire a specified amount of time after a button is pressed. I have tried it though and it still does not work. – Jay Baird Jun 11 '11 at 03:01
0

Ok, found what it was, there was an errant [[UIApplication sharedApplication] cancelAllLocalNotifications]; being sent when entering the background.

Jay Baird
  • 120
  • 1
  • 6
0

Have you tried wrapping the code in a background task?

Alexsander Akers
  • 15,967
  • 12
  • 58
  • 83