2

I want to ask how I can set a reminder from a string and give you a notification 10 minutes before the exact time and after that the UI change from time a to time b.

let a = "04:12"
let b = "11:38"
let c = "15:00"
let d = "18:03"
let e ="18:59"

I am setting up the timer like this but I don't know where I should go from here. This is my code:

extension Date {
     var hour: Int { return Calendar.current.component(.hour, from: self)}
     var minute: Int { return Calendar.current.component(.minute, from: self)}
}

@objc func scheduleTime() {
    timer = Timer(fireAt: Calendar.current.nextDate(after: Date(), matching: DateComponents(hour: 0...23 ~= Date().hour ? 23 : 0), matchingPolicy: .nextTime)!, interval: 0, target: self, selector: #selector(updateUI), userInfo: nil, repeats: false)

    RunLoop.main.add(timer, forMode: .common)
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579
ferryawijayanto
  • 569
  • 4
  • 18
  • You don't need a timer. Just schedule a local notification for the required time – Paulw11 Nov 15 '18 at 06:50
  • @Paulw11 my string time I got from api, and need to update daily. still I can do this with local notification? – ferryawijayanto Nov 15 '18 at 07:03
  • Getting new times is independent of scheduling the notifications. A timer wouldn't help you with that anyway since a timer won't run when the app isn't in the foreground. You should also look at background refresh. – Paulw11 Nov 15 '18 at 07:05
  • @Paulw11 can you show me how to do that? like the background refresh and thing – ferryawijayanto Nov 15 '18 at 07:07

0 Answers0