本地通知“didReceiveLocalNotification”调用两次

我正在处理本地通知使用:

- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif 

并安排本地通知:

 - (void)scheduleNotificationWithInterval:(int)minutesBefore { UILocalNotification *localNotif = [[UILocalNotification alloc] init]; if (localNotif == nil) return; NSDate *fireDate = [NSDate date]; localNotif.fireDate = [fireDate dateByAddingTimeInterval:minutesBefore*60]; localNotif.timeZone = [NSTimeZone defaultTimeZone]; localNotif.repeatInterval = kCFCalendarUnitMinute; localNotif.alertBody = [NSString stringWithFormat:NSLocalizedString(@"LocalEvent notification in %i minutes.", nil),minutesBefore]; localNotif.alertAction = NSLocalizedString(@"View Details", nil); localNotif.applicationIconBadgeNumber = 1; NSDictionary *infoDict = [NSDictionary dictionaryWithObjectsAndKeys:@"This is dict, you can pass info for your notification",@"info",nil]; localNotif.userInfo = infoDict; [[UIApplication sharedApplication] scheduleLocalNotification:localNotif]; [localNotif release]; NSLog(@"Event scheduled"); } 

当我收到通知时, didReceiveLocalNotification:被调用两次。

难道我做错了什么?

请帮忙。

谢谢。

我认为在模拟器中有一个已知的错误,会触发委托通知方法两次。 它不应该发生在设备上,拴在XCode或不。

我也面临着同样的问题,我发现的解决scheme是在didReceiveLocalNotification中写入此代码

 if (state == UIApplicationStateActive) { NSLog(@"UIApplicationStateActive"); } else if(state == UIApplicationStateInactive){ NSLog(@"UIApplicationStateInActive"); } 

在这种情况下,我只是写我希望我的应用程序在通知,活动模式和非活动模式下执行的代码

我怀疑这个通知只要在同一秒内就被重新触发了。 我通过在处理程序中将fireDate设置为nil来修复它:

 - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification { UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:notification.alertAction message:notification.alertBody delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alertView show]; notification.fireDate = nil; } 

我也有同样的发行。 这是由于在AppDelegate的“didFinishLaunchingWithOptions”中调用了“registerUserNotificationSettings”两次。 但是,简单地删除重复的呼叫并没有解决问题。 我不得不删除应用程序,然后重build。 只有这样,双重本地通知问题才得到修复。