[英]How to get the remaining time of pending UNNotificationRequest?
So far, after adding a UNNotificationRequest
to the UNUserNotificationCenter
that contains UNTimeIntervalNotificationTrigger
(Here is the code that I implemented): 到目前为止,加入后
UNNotificationRequest
到UNUserNotificationCenter
包含UNTimeIntervalNotificationTrigger
(下面是我实现的代码):
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)
}
}
It works -fine- as it should, but what I need is to access the remaining time for firing the request trigger. 它可以正常工作,但我需要的是访问剩余时间来触发请求触发器。
For clarity, in my code snippet, I declared: 为了清楚起见,在我的代码段中,我声明了:
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 10.0, repeats: false)
So, if I wait 6 seconds (starting from executing the above code snippet), the remaining time should be 4 seconds. 因此,如果我等待6秒(从执行上述代码段开始),则剩余时间应为4秒。
Also, I tried to fetch the pending requests to check their triggers, as follows: 另外,我尝试获取待处理的请求以检查其触发器,如下所示:
UNUserNotificationCenter.current().getPendingNotificationRequests(completionHandler: { requests in
for request in requests {
print(request.trigger)
}
})
but couldn't find the desired property in UNNotificationTrigger . 但在UNNotificationTrigger中找不到所需的属性。
The question might be is there even a way to access it? 问题可能是什至有一种访问方法? and if it's not, what about a logical workaround to achieve it?
如果不是,那么实现该目标的逻辑解决方法呢?
I get the time interval value from pending UNNotificationRequest Swift4 code 我从待处理的UNNotificationRequest Swift4代码中获取时间间隔值
UNUserNotificationCenter.current().getPendingNotificationRequests(completionHandler: {requests -> () in
for request in requests {
let localTrigger = request.trigger as! UNTimeIntervalNotificationTrigger
localTimeInterval = localTrigger.timeInterval
print (localTimeInterval)
}})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.