Здравствуйте, я пытаюсь сделать приложение Alram для этого я использую Расписание уведомления, используя этот пост https://stackoverflow.com/a/53902489 я установил время, но ничего не получаю, я хочу установить время и напомнить что-то и звонить в определенное время
scheduleNotification(at: createDate(date : 6, month : 2, hour: 17, minute: 15, year: 2019), identifierUnic: stringUUID(), body: "Notification day", titles: "Notification titles1")
func createDate(date: Int, month : Int, hour: Int, minute: Int, year: Int)->Date {
var components = DateComponents()
components.hour = hour
components.minute = minute
components.year = year
components.day = date
components.month = month
components.timeZone = .current
let calendar = Calendar(identifier: .gregorian)
return calendar.date(from: components)!
}
func scheduleNotification(at date: Date, identifierUnic : String, body: String, titles:String) {
let center = UNUserNotificationCenter.current()
center.requestAuthorization(options: [.alert, .sound]) { (granted, error) in }
var anniversary = DateComponents()
anniversary.day = 6
anniversary.month = 2
anniversary.hour = 5
anniversary.minute = 44
anniversary.second = 0
let trigger = UNCalendarNotificationTrigger(dateMatching: anniversary, repeats: true)
let content = UNMutableNotificationContent()
content.title = titles
content.body = body
content.sound = UNNotificationSound.default
content.categoryIdentifier = identifierUnic
let request = UNNotificationRequest(identifier: identifierUnic, content: content, trigger: trigger)
UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
UNUserNotificationCenter.current().add(request) {(error) in
if let error = error {
print(" We had an error: \(error)")
}}
}
func registerLocal() {
let center = UNUserNotificationCenter.current()
center.requestAuthorization(options: [.alert, .badge, .sound]) { (granted, error) in
if granted {
print("Yay!")
} else {
print("D'oh")
}
}
}