【发布时间】:2017-06-01 17:37:42
【问题描述】:
我正在尝试让用户安排通知以在每天的特定时间打开应用程序。到目前为止,我已经能够通过计算从现在到用户选择之间的时间来安排第一个通知,并在 X 秒内安排通知。但是,有没有一种方法可以让我将该通知设置为每天重复?如果您感到困惑,这是我的代码的一部分:
let newTime: Double = Double(totalDifference)
let notifTrigger = UNTimeIntervalNotificationTrigger(timeInterval: newTime, repeats: false)
let request = UNNotificationRequest(identifier: "openApp", content: notif, trigger: notifTrigger)
UNUserNotificationCenter.current().add(request, withCompletionHandler: { error in
if error != nil {
print(error!)
completion(false)
} else {
completion(true)
}
})
非常感谢任何帮助
【问题讨论】:
-
不,我没有使用 UILocalNotification
-
stackoverflow.com/a/42892780/2303865 的可能副本。您只需要删除 weekday 组件即可使其每天运行
标签: ios swift ios10 unusernotificationcenter