簡體   English   中英

iOS - UILocalNotification針對相同的通知觸發了兩次

[英]iOS – UILocalNotification fired twice for same notification

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

請將錯誤報告給http://bugreport.apple.com

話雖如此,之前已經注意到,雖然模擬器中存在錯誤,但設備上似乎還存在錯誤。

請參閱此SO問題的評論和答案: 本地通知“didReceiveLocalNotification”調用兩次

試試這個在我的應用程序中的工作:

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

我希望它對你有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM