mrd
mrd

Reputation: 4699

Scheduled UILocalNotification does not fire after when restarting app or closing app

I am scheduling an UILocalNotification with the following code:

        UILocalNotification *notification = [[UILocalNotification alloc] init];
        notification.fireDate = [[NSDate date] dateByAddingTimeInterval:60];
        notification.repeatInterval = NSMinuteCalendarUnit;
        notification.alertBody = [NSString stringWithFormat:@"Wurmprophylaxe für Lassy”];
        notification.alertAction = @"Wurmprophylaxe";
        //notification.userInfo = userInfo;
        notification.timeZone = [NSTimeZone localTimeZone];
        notification.soundName = UILocalNotificationDefaultSoundName;
        [[UIApplication sharedApplication] scheduleLocalNotification:notification];

The notofication fires until I either terminate the app, restart the app, or re-run through xcode. Simply put, it does not persist. And furthermore it will not fire again, even if the app is running again. It does not matter if the app is in the foreground or not. Once the is terminated, the notification cease to fire and if I list the local notifications, it won't be there anymore. It seems that the UILocalNotification is not being stored. The notification is not delivered, if the app is in foreground, nor background, nor running at all.

Why is it removed between app launches?

Note: If i schedule a new notification, the previous one is removed, too. This is totally weird.

Upvotes: 0

Views: 679

Answers (1)

Mike Sand
Mike Sand

Reputation: 2770

This is normal behavior. "Terminating" an app by the user will aggressively purge any processes the system is managing for the app. (EDIT: This is true for many background processes, but may not be for local notifications.) Reloading a new app through Xcode definitely will.

The normal process for the app is that it first goes into the background state, then later is terminated by the system while in the background. System-managed tasks will continue and the app will be reawakened if necessary.

Upvotes: 1

Related Questions