gpt4 book ai didi

ios - 我们可以避免显示推送通知吗

转载 作者:行者123 更新时间:2023-11-28 20:56:03 25 4
gpt4 key购买 nike

有一个场景,我需要检查用户是否应该根据他的位置接收推送通知。我知道 UNNotificationServiceExtension 帮助我们拦截通知并有助于构建推送内容。但是,对于此类或其他任何地方,我们是否有可能不通过检查用户的位置来显示推送通知?

这并不意味着我每次都想这样做。但只有当我的条件不满足时。在通知内容中,我获取了用户最后一次跟踪的位置,我将用它来与用户的当前位置进行比较。
我经历了this但没有得到令人信服的答案。
注意:我不是在寻找静默推送通知解决方案。

最佳答案

使用 UNUserNotificationCenter 您可以通过 id 取消单个通知。

UNUserNotificationCenter.current().removePendingNotificationRequests(withIdentifiers: [SomeID])

您必须实现 UNUserNotificationCenterDelegate 并实现 userNotificationCenter(_:willPresent)

类似于:

func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
let identifier = notification.request.identifier
let content = notification.request.content
//your logic here
}

关于ios - 我们可以避免显示推送通知吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52310310/

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