iOS - UILocalNotification针对相同的通知触发了两次

时间:2012-07-11 10:28:14

标签: ios uilocalnotification

如果我计划两个UILocalNotification并将它们设置为在完全相同的fireDate上触发。然后在fireDate上的设备上(这不是模拟器错误),application:didReceiveLocalNotification:将触发4次(每次通知2次)。这是一个已知的错误?因为我无法找到任何有关它的信息。

2 个答案:

答案 0 :(得分:1)

请将错误报告给http://bugreport.apple.com

话虽如此,之前已经注意到,虽然模拟器中存在错误,但设备上似乎也存在错误。

请参阅此SO问题的评论和答案:local notification "didReceiveLocalNotification" calls twice

答案 1 :(得分:0)

试试这个在我的应用程序中的工作:

-(IBAction)setRemind:(id)sender{

NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar];

NSDateFormatter *dateFormatter2 = [[NSDateFormatter alloc] init];

[dateFormatter2 setDateFormat:@"YYYY-MM-dd HH:mm:ss"];

//Gets our picker
NSDate *selectedTime = [datePicker date];
strDate2 = [dateFormatter2 stringFromDate:selectedTime];
NSDate *Date=[dateFormatter2 dateFromString:strDate2];

NSDateComponents *dateComponents = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit ) fromDate:Date];

// Set up the fire time
NSDateComponents *dateComp = [[NSDateComponents alloc] init];
[dateComp setDay:[dateComponents day]];
[dateComp setMonth:[dateComponents month]];
[dateComp setYear:[dateComponents year]];
[dateComp setHour:9];
[dateComp setMinute:00];
[dateComp setSecond:00];
[dateComp release];

NSDate *date = [calendar dateFromComponents:dateComp];
[self scheduleAlarmForDate:date message:txtDescri.text];

}


-(IBAction)scheduleAlarmForDate:(NSDate*)date message:(NSString*)msg
{

//====== TO SEE OLD NOTIFI=======
UIApplication *Ap = [UIApplication sharedApplication];
NSArray *arr = [Ap scheduledLocalNotifications];
NSLog(@"Old Notifications :>> %@",arr);

UIApplication* app = [UIApplication sharedApplication];
UILocalNotification *alarm = [[UILocalNotification alloc] init];

// Create a new notification
alarm.fireDate = date;
NSLog(@"fireDate IS >> %@", alarm.fireDate);
alarm.timeZone = [NSTimeZone localTimeZone];
alarm.alertBody = msg;
NSLog(@"msg IS >> %@",msg);
alarm.alertAction = @"Show";
alarm.repeatInterval = 0;
alarm.soundName = UILocalNotificationDefaultSoundName;
alarm.applicationIconBadgeNumber = 1;
[app scheduleLocalNotification:alarm];
 [alarm release];
} 

我希望它对你有所帮助。