Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func addNotify(person: Person, firedate: Date) {
- let notificationContent = UNMutableNotificationContent()
- var text = ""
- var prazdnuet = "birthdayToday1".localized
- if person.day == getDay(date: getMyDate(string: firedate.description)) && person.month == getMonth(date: getMyDate(string: firedate.description)) {
- text = "\(prazdnuet)"
- }
- else {
- prazdnuet = "birthdaycherez1".localized
- text = "\(prazdnuet) \(daysTo(birthday: person.date, firedate: firedate)) \(daysSklon(day: Int(daysTo(birthday: person.date, firedate: firedate))!))"
- }
- notificationContent.body = text
- notificationContent.badge = howBirthdayToday() as NSNumber
- //сколько днюх сегодня
- // let imageName = "1024"
- // guard let imageURL = Bundle.main.url(forResource: imageName, withExtension: "png") else { return }
- //
- // let attachment = try! UNNotificationAttachment(identifier: imageName, url: imageURL, options: .none)
- //
- // notificationContent.attachments = [attachment]
- notificationContent.title = person.name
- notificationContent.userInfo = ["personID":person.id]
- if GlobalVars.melody != "nosound".localized {
- notificationContent.sound = UNNotificationSound(named: UNNotificationSoundName(rawValue: GlobalVars.melody + ".caf"))
- }
- let notificationTrigger = UNCalendarNotificationTrigger.init(dateMatching: NSCalendar.current.dateComponents([.day, .month, .year, .hour, .minute], from: firedate), repeats: false)
- let notificationRequest = UNNotificationRequest(identifier: "\(String(person.id))#\(firedate.description)", content: notificationContent, trigger: notificationTrigger)
- UNUserNotificationCenter.current().add(notificationRequest) { (error) in
- if let error = error {
- print("Unable to Add Notification Request (\(error), \(error.localizedDescription))")
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement