Friday, September 4, 2026
HomeiOS Developmentios - There's a approach to set an notification to set off...

ios – There’s a approach to set an notification to set off within the first time in 8 hours after which in one other time, like 4 in 4 hours in swift

[ad_1]

I am making an attempt to make an algorithm that receives a time for the primary dose of the medication, and from there it triggers an alarm for X time from now, additionally chosen by the person.

Instance: First dose of the medication was at 12:00 and I need to take it each 8 hours. Due to this fact, the primary alarm have to be set at 20:00 and the next, each 8 hours.

The issue is that if I set the primary alarm to the specified time + 8, the alarm is not going to go off at 20, however sure. And if I solely use it each 8 hours, I can not set the beginning time

func notifications(identify: String, timeToTime: String, firstTime: String) {
    let middle = UNUserNotificationCenter.present()
    getTimeForNotification(string: firstTime)

    let content material = UNMutableNotificationContent()
    content material.title = "It is time to take (identify)"
    content material.physique = "Keep in mind that you will need to ingest this drugs from (timeToTime)"
    content material.sound = UNNotificationSound.default
    
    let timeInterval = handleToInt(time: timeToTime) // * 3600
    let set off = UNTimeIntervalNotificationTrigger(
        timeInterval: timeInterval,
        repeats: true)
    
    let request = UNNotificationRequest(identifier: identify, content material: content material, set off: set off)
    
    middle.add(request)
}

first time is the variable that shops the time of the primary dose, as a double, by the tactic getTimeForNotification() and timeInterval is the time, ex: 8 in 8, 12 in 12

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments