我想从日期开始重复本地通知 . 例如:
StartDate: 25 June 2018
Todays Date: 21 June 2018
我被困在这里 . 下面的代码正在运行,但它从今天开始发送本地通知,而不是2018年6月25日 .
请查看我的本地通知功能:
func scheduleDosageLocalNotification(date: Date) {
reminder.dosageIdentifier = "Dosage_Day"
var calendar = Calendar.current
calendar.timeZone = TimeZone.current
let notificationContent = UNMutableNotificationContent()
// Configure Notification Content
notificationContent.title = "DOSAGE REMINDER"
notificationContent.body = "Remember to take your TEST tablet dialy."
// Set Category Identifier
notificationContent.categoryIdentifier = Notification.Category.First
var components = calendar.dateComponents([.hour, .minute], from: date)
components.hour = 08
components.minute = 00
let notificationTrigger = UNCalendarNotificationTrigger(dateMatching: components, repeats: true)
// let notificationTrigger = UNTimeIntervalNotificationTrigger(timeInterval: interval!, repeats: true)
// Create Notification Request
let identifier = "Dosage_Day"
let notificationRequest = UNNotificationRequest(identifier: identifier, content: notificationContent, trigger: notificationTrigger)
// Add Request to User Notification Center
UNUserNotificationCenter.current().add(notificationRequest) { (error) in
if let error = error {
print("Unable to Add Notification Request (\(error), \(error.localizedDescription))")
}
Utilities.saveContextForAppInfo()
}
}
它应该每天重复,但从6月25日开始 . Thanks in Advance!!
2 回答
试试这个,
如果您想在设备中测试通知,
假设下次通知于2018年6月25日晚上7点到达,您将设备设置中的日期修改为下午6点59分和2018年6月25日,或者您将设备设置中的日期修改为2018年下午7点1分和2018年6月25日
预定通知将在那时到达,
它只是样本,它将在每个特定的工作日重复通知 . 如果您想重复通知,您应该设置任何订单,例如每天,每周,每周一等 . 否则,您应该使用唯一ID注册特定日期(无日订单日期)的多个通知 .
参考这个 - How to show multiple local notifications?
如果您希望每天重复通知,但希望跳过第一次出现的通知 . 我不认为这是可能的 . 还有一个类似的问题
Scheduling local notifications to repeat daily from tomorrow in Swift
祝好运!
尝试下面的代码行:
我改变了
至
Updated answer :
}}
快乐编码....