Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func notification(date: Date, repeatUnit: NSCalendar.Unit?) -> UILocalNotification {
- let notification = UILocalNotification()
- notification.category = "ReminderCategory"
- notification.alertTitle = "Test"
- notification.alertBody = "Test Body"
- notification.soundName = "Sound1.m4a"
- notification.fireDate = date
- notification.repeatInterval = repeatUnit ?? NSCalendar.Unit(rawValue: 0)
- notification.timeZone = TimeZone.init(secondsFromGMT: 0)!
- return notification
- }
- let center = UNUserNotificationCenter.current()
- let content = UNMutableNotificationContent()
- content.title = "Title"
- content.body = "Your text"
- content.categoryIdentifier = "reminder-notification"
- content.sound = UNNotificationSound.default()
- var dateComponents = DateComponents()
- dateComponents.hour = Calendar.current.component(.hour, from: date)
- dateComponents.minute = Calendar.current.component(.minute, from: date)
- let trigger = UNCalendarNotificationTrigger(dateMatching: dateComponents, repeats: false)
- let request = UNNotificationRequest(identifier: identifier, content: content, trigger: trigger)
- center.add(request)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement