【发布时间】:2020-06-18 01:56:04
【问题描述】:
我想在用户从 DatePicker 中选择时设置每日通知,但我不知道如何将选定的小时和分钟转换为 DateComponents 以匹配 UNCalendarNotificationTrigger。
这是我的日期选择器:
DatePicker("Choose time of notif", selection: $notifTime, displayedComponents: .hourAndMinute)
这是我的通知触发器:
var dateComponents = DateComponents()
dateComponents = notifTime
let trigger = UNCalendarNotificationTrigger(dateMatching: dateComponents, repeats: true)
【问题讨论】:
标签: swift datepicker notifications uikit swiftui