gpt4 book ai didi

ios - UNNotificationRequest 需要唯一标识符,但也会触发重复项

转载 作者:行者123 更新时间:2023-12-05 05:19:20 24 4
gpt4 key购买 nike

我这样调用本地通知

let center = UNUserNotificationCenter.current()
let content = UNMutableNotificationContent()
content.title = title
content.body = text
content.categoryIdentifier = category
content.userInfo = map
content.sound = UNNotificationSound.default()
content.setValue("YES", forKeyPath: "shouldAlwaysAlertWhileAppIsForeground")
let request = UNNotificationRequest(identifier: "testing", content: content, trigger: nil)
center.add(request)

每次都使用相同的 UNNotificationRequest 标识符(不变的字符串)。根据the docs :

identifier

A unique identifier for the request (if identifier is not unique, a new notification request object is not created). You can use this identifier later to cancel a request that is still pending. This parameter must not be nil.

本地通知在我每次触发时都会触发,即使是在应用程序的同一个实例中。标识符始终相同。文档有错吗?

最佳答案

此时文档已更正且更准确: https://developer.apple.com/documentation/usernotifications/unnotificationrequest/1649633-init

The system uses the identifier parameter to determine how to handlethe request:

  • If you provide a unique identifier, the system creates a new notification.
  • If the identifier matches a previously delivered notification, the system alerts the user again, replaces the old notification with thenew one, and places the new notification at the top of the list.
  • If the identifier matches a pending request, the new request replaces the pending request.

关于ios - UNNotificationRequest 需要唯一标识符,但也会触发重复项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46437880/

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