Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. func addNotify(person: Person, firedate: Date) {
  2.  
  3. let notificationContent = UNMutableNotificationContent()
  4. var text = ""
  5. var prazdnuet = "birthdayToday1".localized
  6.  
  7. if person.day == getDay(date: getMyDate(string: firedate.description)) && person.month == getMonth(date: getMyDate(string: firedate.description)) {
  8. text = "\(prazdnuet)"
  9. }
  10. else {
  11. prazdnuet = "birthdaycherez1".localized
  12. text = "\(prazdnuet) \(daysTo(birthday: person.date, firedate: firedate)) \(daysSklon(day: Int(daysTo(birthday: person.date, firedate: firedate))!))"
  13. }
  14. notificationContent.body = text
  15. notificationContent.badge = howBirthdayToday() as NSNumber
  16. //сколько днюх сегодня
  17.  
  18. // let imageName = "1024"
  19. // guard let imageURL = Bundle.main.url(forResource: imageName, withExtension: "png") else { return }
  20. //
  21. // let attachment = try! UNNotificationAttachment(identifier: imageName, url: imageURL, options: .none)
  22. //
  23. // notificationContent.attachments = [attachment]
  24.  
  25. notificationContent.title = person.name
  26. notificationContent.userInfo = ["personID":person.id]
  27.  
  28. if GlobalVars.melody != "nosound".localized {
  29. notificationContent.sound = UNNotificationSound(named: UNNotificationSoundName(rawValue: GlobalVars.melody + ".caf"))
  30. }
  31. let notificationTrigger = UNCalendarNotificationTrigger.init(dateMatching: NSCalendar.current.dateComponents([.day, .month, .year, .hour, .minute], from: firedate), repeats: false)
  32.  
  33. let notificationRequest = UNNotificationRequest(identifier: "\(String(person.id))#\(firedate.description)", content: notificationContent, trigger: notificationTrigger)
  34. UNUserNotificationCenter.current().add(notificationRequest) { (error) in
  35. if let error = error {
  36. print("Unable to Add Notification Request (\(error), \(error.localizedDescription))")
  37. }
  38.  
  39. }
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement