我有下面這行代碼來在每1分鐘後生成本地通知(對於測試),它在以下情況下可以很好地工作。當localNotification.alertBody被評論時,DidReceivedLocalNotificaiton沒有被調用
- 當應用程序處於運行狀態。
- 當應用程序處於後臺狀態並且localNotification.alertBody = @「接收到本地通知」時未被註釋。
現在,當我評論「localNotification.alertBody」它應用程序處於運行狀態時工作正常,但應用程序處於後臺狀態時不起作用。
以下是創建本地通知的代碼行。
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
[localNotification setRepeatInterval:NSMinuteCalendarUnit];
localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.repeatCalendar = [NSCalendar currentCalendar];
localNotification.fireDate = fireDateOfNotification;
//localNotification.alertBody = @"Local Notification Received";
localNotification.repeatInterval = NSMinuteCalendarUnit;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
[localNotification release];
在 - (空)applicationDidEnterBackground:(UIApplication的*)應用
bgTask = [application beginBackgroundTaskWithExpirationHandler: ^{
dispatch_async(dispatch_get_main_queue(), ^{
[application endBackgroundTask:self->bgTask];
self->bgTask = UIBackgroundTaskInvalid;
嗯,我想要做的是,如果應用程序處於後臺狀態,那麼我不想顯示任何消息,並讓didReceiveLocalNotification調用...實際上,我什麼時候都不想顯示任何消息並調用didReceiveLocalNotification間隔後。 – 2011-12-19 07:57:47
這應該由您的代碼來實現。你確定,'application:didReceiveLocalNotification:'沒有被調用嗎?你有沒有把一些日誌記錄到該方法? – tobiasbayer 2011-12-19 08:07:01
請使用代碼更新您的問題,而不是將其放入評論中以獲得更好的可讀性。 – tobiasbayer 2011-12-19 09:48:30