开发者

iPhone app crashing on local notification

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";
        localNo开发者_StackOverflow中文版tif.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];
}


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


on which device you are testing on? where do you check if the device is iPhone3G? This code is not going to run on Iphone3g even it is on iOS4 as iPhone3G is not supported multitasking. Rest of the code looks OK.


Yes It is an iOS 4.1 issue, I've also faced same kind of issue "Simulator crashed" but I've also experienced another issue that is: If we fire more-than one Local-Notification in the background, then it also crashed iPhone iOS :S

I'm unable to find any workaround to execute more-than one Local Notification. Apple Development team must have to validate Local-Notification deeply.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜