admin管理员组文章数量:1289556
I am sending push notifications on iOS, and I can receive and display them correctly. I want to be able to dismiss notifications that have been read server-side (e.g. on a different device) so I am trying to send a custom payload with a badge counter update, that specifies what notification IDs to remove. I then use removeDeliveredNotifications on the IDs I get. However, it doesn't seem to be working. I am setting the identifier using the apns-collapse-id
header and I do see that reflected on the client side. Any ideas what I might be doing wrong?
func userNotificationCenter(
_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void
) {
let customPayload = notification.request.content.userInfo
if let dismissedNotifications = customPayload["dismissed_notifications"] as? [String] {
center.removeDeliveredNotifications(withIdentifiers: dismissedNotifications)
}
completionHandler([.banner, .sound, .badge])
}
I've also tried looking for the notification IDs in getDeliveredNotifications
and the notification IDs I am sending do in fact correspond to received notifications. But this also does not result in the notifications getting dismissed on the device.
center.getDeliveredNotifications(completionHandler: { notifications in
var identifiersToRemove: [String] = []
for notification in notifications {
if dismissedNotifications.contains(notification.request.identifier) {
identifiersToRemove.append(notification.request.identifier)
}
}
center.removeDeliveredNotifications(withIdentifiers: identifiersToRemove)
})
本文标签: swiftDismissing notifications on iOSStack Overflow
版权声明:本文标题:swift - Dismissing notifications on iOS - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741468127a2380435.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论