我称之为本地通知,如
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标识符(一个不变的字符串)。根据医生们
标识符 请求的唯一标识符(如果标识符不是唯一的,则不创建新的通知请求对象)。以后可以使用此标识符取消仍在挂起的请求。此参数不得为零。
本地通知每次触发时都会触发,即使在应用程序的同一个实例中也是如此。标识符总是相同的。医生是错的吗?
发布于 2021-08-20 14:32:30
此时,文档得到了更正,并且更加准确:https://developer.apple.com/documentation/usernotifications/unnotificationrequest/1649633-init
系统使用标识符参数来确定如何处理请求:
https://stackoverflow.com/questions/46437880
复制相似问题