2010-09-16 74 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。