UILocalNotification已经大幅贬值,我想更新我的代码到UserNotification框架:UserNotification 3天,然后每天重复/小时 - iOS的10
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 // ...
}
相关? [如何在iOS 10用户通知上设置NSCalendarUnitMinute repeatInterval?](http://stackoverflow.com/q/37804287/2415822) – JAL
相关,但似乎没有来自UserNotifications支持的折旧UILocalNotifications的.repeatInterval。寻找如何在新框架中处理这个问题,这样我就可以将我的代码从折旧的代码中移出。 –
建议您提高雷达 – Wain