gpt4 book ai didi

ios - 如何获取待处理的 UNNotificationRequest 的剩余时间?

转载 作者:行者123 更新时间:2023-11-28 08:09:19 25 4
gpt4 key购买 nike

到目前为止,在将 UNNotificationRequest 添加到包含 UNTimeIntervalNotificationTriggerUNUserNotificationCenter 之后(这是我实现的代码):

let center = UNUserNotificationCenter.current()
center.requestAuthorization(options: [.alert, .badge, .sound]) { (granted, error) in
if granted {
let content = UNMutableNotificationContent()
center.delegate = self
content.title = "title"
content.body = "body"

let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 10.0, repeats: false)
let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: trigger)
center.add(request)
}
}

它可以正常工作,但我需要的是获取触发请求触发器的剩余时间。

为清楚起见,在我的代码片段中,我声明:

让触发器 = UNTimeIntervalNotificationTrigger(timeInterval: 10.0, repeats: false)

所以,如果我等待 6 秒(从执行上面的代码片段开始),剩余时间应该是 4 秒。

此外,我尝试获取待处理的请求以检查它们的触发器,如下所示:

UNUserNotificationCenter.current().getPendingNotificationRequests(completionHandler: { requests in
for request in requests {
print(request.trigger)
}
})

但在 UNNotificationTrigger 中找不到所需的属性.

问题可能是有没有办法访问它?如果不是,实现它的逻辑解决方法如何?

最佳答案

我从未决的 UNNotificationRequest 中获取时间间隔值Swift4代码

UNUserNotificationCenter.current().getPendingNotificationRequests(completionHandler: {requests -> () in
for request in requests {
let localTrigger = request.trigger as! UNTimeIntervalNotificationTrigger
localTimeInterval = localTrigger.timeInterval
print (localTimeInterval)
}})

关于ios - 如何获取待处理的 UNNotificationRequest 的剩余时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44116585/

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