- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想开发一个提醒应用程序,当我们设置提醒时需要发送本地通知。我开发了一些代码,即使我设置了多个通知,也只触发一个通知。如果我在晚上 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!)
}
我想在每次创建提醒时发送通知。帮我解决这个问题。谢谢...
最佳答案
每次使用不同的标识符。它会起作用
关于iOS - 安排多个本地通知,UNCalendarNotificationTrigger,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43291468/
好的 - 我现在对这段代码感到非常沮丧,准备放弃!基本上,当模拟到模拟器或实际设备时,我得到 requestAuthorisation 可以正常工作,但触发器不会启动。我在网上关注了几个人,他们的代码
我正在使用以下方法来每小时触发一次本地通知。 let reminderTrigger = UNCalendarNotificationTrigger.init(dateMatching: NSCale
先生们早上好 我知道这样使用 UNCalendarNotificationTrigger: var dateComponents = DateComponents() dateComponents.h
我想开发一个提醒应用程序,当我们设置提醒时需要发送本地通知。我开发了一些代码,即使我设置了多个通知,也只触发一个通知。如果我在晚上 7:30、晚上 7:31、晚上 7:32 设置提醒,则通知仅在晚上
在an earlier question我提到了安排本地通知的问题。问题的真正原因是我曾经使用以下代码来创建触发器,但它不起作用: let calendar = ... let notificatio
本地通知应该在 25-9-2021 发出。这是火灾时间的打印对象 ▿ year: 2021 month: 9 day: 26 isLeapMonth: false year : 2021 month
我的应用程序必须每隔 n 天提醒用户一些事情。 目前,我有 var dateComponents = DateComponents() dateComponents.hour = userHour d
我注意到,如果我创建一个带有自定义日期的 UNCalendarNotificationTrigger,它不会被添加,除非我输入:让 trigger = UNCalendarNotificationTr
我是一名优秀的程序员,十分优秀!