ios - 在 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)
}
解决方案
推荐阅读
- mysql - 如何以最佳方式从 MySQL 和 Neo4j 等两个不同的数据库中删除相同的数据?
- javascript - jQuery 对象方法被多次调用
- websocket - Django 频道 | 如何确保消息的顺序和传递
- python - 我无法理解 ax.set_aspect() 的工作原理
- php - 用 php 解析一个短语(用空格分隔的单词)
- dart - 参数类型'Future
'不能分配给参数类型'String' - python - Django Admin Form,设置只读字段(用户外键字段)的默认值
- docker - 使用 docker 的 7.7 上的 Elasticsearch Cluster 问题
- python - 删除满足针对多列评估的条件的 DataFrame 的行
- r - Caret train 方法在尝试使用 H2o 包时抱怨:“出了点问题;所有准确度度量值都丢失了”