0

我想開發一個提醒應用程序,當我們設置提醒時需要發送本地通知。我開發了一些只觸發一個通知的代碼,即使我設置了多個通知。如果我在下午7:30,7:31 PM,7:32 PM設置提醒,通知僅在下午7:32顯示。iOS - 安排多個本地通知,UNCalenderNotificationTrigger

這裏是我的代碼

func scheduleNotification(at date: Date) { 
    let calendar = Calendar(identifier: .gregorian) 
    let components = calendar.dateComponents(in: .current, from: date) 
    let newComponents = DateComponents(calendar: calendar, timeZone: .current, month: components.month, day: components.day, hour: components.hour, minute: components.minute) 
    let trigger = UNCalendarNotificationTrigger(dateMatching: newComponents, repeats: true) 
    let content = UNMutableNotificationContent() 
    content.title = "Reminder" 
    content.body = "To day is the last date for the payment of your card. Please make payment today." 
    content.sound = UNNotificationSound.default() 
    content.categoryIdentifier = "PaymentReminderIdentifier" 
    let request = UNNotificationRequest(identifier: "ReminderNotification", content: content, trigger: trigger) 
    UNUserNotificationCenter.current().delegate = self 
    //UNUserNotificationCenter.current().removeAllPendingNotificationRequests() 
    UNUserNotificationCenter.current().add(request) {(error) in 
     if let error = error { 
      print("Uh oh! We had an error: \(error)") 
     } 
    } 
} 

//

func notif() { 
    let selectedDate = fullDate 
    print("Selected date: \(selectedDate)") 
    let delegate = UIApplication.shared.delegate as? AppDelegate 
    delegate?.scheduleNotification(at: selectedDate!) 
} 

我想,當我創建的提醒通知傳遞的每一次。 幫我解決了這個問題。謝謝...

回答

2

每次使用不同的標識符。它會工作