gpt4 book ai didi

ios - 立即使用 UNUserNotificationCenter 调用本地通知

转载 作者:行者123 更新时间:2023-11-30 12:00:11 25 4
gpt4 key购买 nike

我现在如何调用本地通知?而不是在未来设定一个时间间隔?此代码将在未来 5 秒后显示通知。我希望现在就调用它。

let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5.0, repeats: false)

let notificationRequest = UNNotificationRequest(identifier: "notification", content: notificationContent, trigger: trigger)

UNUserNotificationCenter.current().add(notificationRequest) { (error) in
if let error = error {
//error
}
}

最佳答案

因为timeInterval必须大于0,所以可以尝试在timeInterval中放入0.1。

或者您可以在特定时间触发本地通知。(现在时间)

let date = Date()
let calendar = Calendar.current
let components = calendar.dateComponents([.timeZone], from: date)
let trigger = UNCalendarNotificationTrigger(dateMatching: components, repeats: true)

关于ios - 立即使用 UNUserNotificationCenter 调用本地通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47341873/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com