首页 > 解决方案 > 在 iOS 中设置提醒

问题描述

我想问一下如何从字符串中设置提醒,并在确切时间前 10 分钟给你一个通知,之后 UI 从时间 a 变为时间 b。

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

我正在设置这样的计时器,但我不知道我应该从这里去哪里。这是我的代码:

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)
}

标签: iosswifttimerreminders

解决方案


推荐阅读