2012-07-11 44 views
3

如果我安排兩個UILocalNotification s並將它們設置爲在相同的fireDate觸發。然後在設備上(這不是模擬器錯誤)在fireDate application:didReceiveLocalNotification:將觸發4次(每次通知2次)。這是一個已知的錯誤?因爲我一直無法找到任何有關它的信息。iOS - UILocalNotification針對相同的通知發射兩次

回答

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]; 
} 

我希望這對您有所幫助。