views:

128

answers:

2

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];
}
+1  A: 

Hi winsmith

It seems to be an iOS 4.1 bug. I have similar problems with my app which used to work with 4.0. Also other people reported problems like that in the apple developer forums. Waiting for an response from apple.

Greetings,

Ben

Ben Zwak
Have some more infos about the problem. But in my case it seems that has not to do with local notification, but with CLLocationManager, especially significantLocationChanges.
Ben Zwak
I'm using 4.0 at the moment. So this is out.
winsmith