2010-09-16 75 views
0

这是奇怪。我的应用程序会在本地通知发送到后台时安排本地通知,并且在第一次通知正确显示时,只要后面的通知被触发,整个应用程序就会崩溃。是的,在后台。虽然没有代码正在执行。iPhone应用程序崩溃本地通知

没有给出控制台输出,我只是得到一个对话框,在iPhone模拟器中显示“模拟应用程序退出”。在实际的iPhone上,我被扔回跳板。

以下是通知的相关代码。谢谢你的帮助。

- (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

用调试器进行堆栈跟踪。另外,你会得到什么样的退出状态? – geon 2010-09-16 09:55:53

+0

看起来很愚蠢,但是,我该怎么做?当应用程序进入后台时,似乎所有的调试输出都会停止。 – winsmith 2010-09-20 09:35:34

+0

@winsmith你有调试吗?你为SIGABRT得到了什么? – 2014-03-26 11:47:22

回答

1

它似乎是一个iOS 4.1的错误。我遇到类似的问题,我的应用程序曾经使用4.0。另外还有人在苹果开发者论坛上报告过类似的问题。等待苹果的回应。

问候,

+0

有关于这个问题的更多信息。但在我看来,这似乎没有与本地通知,但与CLLocationManager,特别是significantLocationChanges。 – 2010-09-16 16:29:00

+0

我目前使用4.0。所以这个就出来了。 – winsmith 2010-09-20 09:36:09

1

所用的设备要测试吗?你在哪里检查设备是否是iPhone3G?此代码不会在Iphone3上运行,即使它在iOS4上也不会支持,因为iPhone3G不支持多任务处理。 其余代码看起来没问题。

+0

但是为什么它会崩溃调试器呢?那一个被设置为iPhone 4.无论如何,我会尽力的,谢谢你的回答。 – winsmith 2010-11-08 18:15:04

1

是这是一个iOS 4.1的问题,我也面临同样的问题“模拟器崩溃”,但我也遇到了另一个问题: 如果我们在后台触发多个本地通知,那么它也坠毁iPhone的iOS:S

我无法找到任何解决方法来执行多个本地通知。 Apple开发团队必须深入验证Local-Notification。