iOS - 安排多个本地通知,UNCalenderNotificationTrigger
Posted
技术标签:
【中文标题】iOS - 安排多个本地通知,UNCalenderNotificationTrigger【英文标题】:iOS - schedule multiple local notifications, UNCalenderNotificationTrigger 【发布时间】:2017-04-08 07:38:34 【问题描述】:我想开发一个提醒应用,当我们设置提醒时需要发送本地通知。我开发了一些代码,即使我设置了多个通知,也只会触发一个通知。如果我在晚上 7:30、晚上 7:31、晚上 7:32 设置提醒,则通知仅在晚上 7:32 显示。
这是我的代码
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!)
我想在每次创建提醒时发送通知。 帮我解决这个问题。谢谢...
【问题讨论】:
【参考方案1】:每次使用不同的标识符。它会工作
【讨论】:
以上是关于iOS - 安排多个本地通知,UNCalenderNotificationTrigger的主要内容,如果未能解决你的问题,请参考以下文章