Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. func notification(date: Date, repeatUnit: NSCalendar.Unit?) -> UILocalNotification {
  2. let notification = UILocalNotification()
  3. notification.category = "ReminderCategory"
  4. notification.alertTitle = "Test"
  5. notification.alertBody = "Test Body"
  6. notification.soundName = "Sound1.m4a"
  7. notification.fireDate = date
  8. notification.repeatInterval = repeatUnit ?? NSCalendar.Unit(rawValue: 0)
  9. notification.timeZone = TimeZone.init(secondsFromGMT: 0)!
  10.  
  11. return notification
  12. }
  13.  
  14. let center = UNUserNotificationCenter.current()
  15.  
  16. let content = UNMutableNotificationContent()
  17. content.title = "Title"
  18. content.body = "Your text"
  19. content.categoryIdentifier = "reminder-notification"
  20. content.sound = UNNotificationSound.default()
  21.  
  22.  
  23. var dateComponents = DateComponents()
  24. dateComponents.hour = Calendar.current.component(.hour, from: date)
  25. dateComponents.minute = Calendar.current.component(.minute, from: date)
  26.  
  27. let trigger = UNCalendarNotificationTrigger(dateMatching: dateComponents, repeats: false)
  28.  
  29. let request = UNNotificationRequest(identifier: identifier, content: content, trigger: trigger)
  30. center.add(request)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement