IOS UILocalNotification is not displayed during application in background

FIXED - Well, found it to be, happened weird [[UIApplication sharedApplication] cancelAllLocalNotifications];when I didn't expect it.

Well, there is your problem.

Thanks for helping everyone, sorry to just get dumb coder syndrome.

I created a local notification:

- (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 gives the correct firedate value of 10 seconds in the future. If I do not leave my application, I receive a successful callback application:didReceiveLocalNotification:.

Hiccups are here if I click a button to schedule this notification and click the home button to put it in the background. If I do this, the notification never fires and I never get the warning from the OS.

- ? , Apple , - .

. .

+3
3

, , , [[UIApplication sharedApplication] cancelAllLocalNotifications]; .

0

Have you tried wrapping the code in a background job?

0
source

All Articles