This is weird. My application schedules local notifications whenever it is sent into the background, and while the first notification is being displayed correctly, as soon as the one after that should be fired, the whole application crashes. Yes, in the background. While no code is being executed.
No console output is given, I just get a dialog box that says "The simulated application quit" in iPhone simulator. On an actual iPhone I get dumped back to the springboard.
Here's the relevant code for the notifications. Thanks for your help.
- (void)scheduleLocalNotificationsForAlarmsWithNextAlarmAt:(NSDate *)theFireDate ofType:(int)workPlayType {
BOOL backgroundSupported = NO;
UIDevice* device = [UIDevice currentDevice];
if ([device respondsToSelector:@selector(isMultitaskingSupported)])
backgroundSupported = device.multitaskingSupported;
if(!backgroundSupported) return;
int work_minutes = [[NSUserDefaults standardUserDefaults] integerForKey:@"work_minutes_preference"];
int play_minutes = [[NSUserDefaults standardUserDefaults] integerForKey:@"play_minutes_preference"];
int workPlayStatusForNotif = workPlayType;
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil)
return;
if (workPlayStatusForNotif == 1) {
localNotif.alertBody = @"Work";
localNotif.repeatInterval = work_minutes;
} else {
localNotif.alertBody = @"Play";
localNotif.repeatInterval = play_minutes;
}
localNotif.fireDate = theFireDate;
localNotif.timeZone = [NSTimeZone defaultTimeZone];
localNotif.alertAction = NSLocalizedString(@"View Details", nil);
localNotif.soundName = @"ding.caf";
localNotif.applicationIconBadgeNumber = 0;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
[localNotif release];
// now the other one
localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil)
return;
if (workPlayStatusForNotif == 0) {
localNotif.alertBody = @"Work";
localNotif.fireDate = [theFireDate dateByAddingTimeInterval:(float)work_minutes*60];
localNotif.repeatInterval = work_minutes;
} else {
localNotif.alertBody = @"Play";
localNotif.fireDate = [theFireDate dateByAddingTimeInterval:(float)play_minutes*60];
localNotif.repeatInterval = play_minutes;
}
localNotif.timeZone = [NSTimeZone defaultTimeZone];
localNotif.alertAction = NSLocalizedString(@"View Details", nil);
localNotif.soundName = @"ding.caf";
localNotif.applicationIconBadgeNumber = 0;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
[localNotif release];
}