UILocalNotification has been discounted, so I would like to update my code to the scope of 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)
How can I set a similar daily or hourly repetition using the UserNotification structure after waiting for an initial notification?
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
date ios10 swift repeat notifications
Greg robertson
source share