Hey,
my aim is to build a local notification which should be triggered at three specific times a day. The notification body should be a different one every day.
This is the String Array of which one string should be shown in the notifiaction.
It doesn´t matter if the String gets choosen randomly or in the sequence the array is ordered.
var arrayText: [String] = ["1",
"2",
"3",
"4",
"5"]
This is how far I got. Just a normal local notification with everytime the same body text and only one trigger a day, but I want 3 triggers a day and not everytime the same body text.
let center = UNUserNotificationCenter.current()
center.requestAuthorization(options: [.alert, .sound]) { (granted, error) in
if !granted {
print("Something went wrong")
}
}
let content = UNMutableNotificationContent()
content.title = "text"
content.body = "text"
content.sound = UNNotificationSound.default
let gregorian = Calendar(identifier: .gregorian)
let now = Date()
var components = gregorian.dateComponents([.year, .month, .day, .hour, .minute, .second], from: now
components.hour = 8
components.minute = 0
components.second = 0
let date = gregorian.date(from: components)!
let triggerDaily = Calendar.current.dateComponents([.hour, .minute, .second], from: date)
let trigger = UNCalendarNotificationTrigger(dateMatching: triggerDaily, repeats: true)
let uuidString = UUID().uuidString
let request = UNNotificationRequest(identifier: uuidString, content: content, trigger: trigger)
center.add(request, withCompletionHandler: { (error) in
if let error = error {
// Something went wrong
}
})
Help would be awesome. And thank you for every helpfull answer
Yours sincerely
Tell aka. Relbot