【发布时间】:2016-11-17 18:13:21
【问题描述】:
UILocalNotification 已被贬值,所以我想将我的代码更新为 UserNotification 框架:
let alertDays = 3.0
let alertSeconds = alertDays * 24.0 * 60.0 * 60.0
let localNotification:UILocalNotification = UILocalNotification()
localNotification.alertAction = "Reminder"
localNotification.alertTitle = "Reminder Title"
localNotification.alertBody = "Reminder Message"
localNotification.fireDate = Foundation.Date(timeIntervalSinceNow: alertSeconds)
localNotification.repeatInterval = .day
UIApplication.shared().scheduleLocalNotification(localNotification)
在等待初始通知后,如何使用 UserNotification 框架设置类似的每日或每小时重复?
let alertDays = 3.0
let alertSeconds = alertDays * 24.0 * 60.0 * 60.0
let content: UNMutableNotificationContent = UNMutableNotificationContent()
content.title = "Reminder Title"
content.subtitle = "Reminder Subtitle"
content.body = "Reminder Message"
let calendar = Calendar.current
let alarmTime = Foundation.Date(timeIntervalSinceNow: alertSeconds)
let alarmTimeComponents = calendar.components([.day, .hour, .minute], from: alarmTime)
let trigger = UNCalendarNotificationTrigger(dateMatching: alarmTimeComponents, repeats: true)
let request = UNNotificationRequest(identifier: workoutAlarmIdentifier,
content: content,
trigger: trigger)
UNUserNotificationCenter.current().add(request)
{
(error) in // ...
}
【问题讨论】:
-
相关但似乎没有来自 UserNotifications 支持的已折旧 UILocalNotifications 的 .repeatInterval。寻找在新框架中如何处理这个问题,以便我可以将我的代码从折旧的框架中移出。
-
建议你提高雷达
-
Greg Robertson,您是否设法将接受的答案与本地 UNNotifications 一起使用?据我所知,它只适用于远程通知......
-
这个答案可能会有所帮助:stackoverflow.com/questions/54076050/…
标签: swift date notifications repeat ios10