更改代码中的推送通知声音:iOS

发布于 2025-01-29 10:18:55 字数 613 浏览 2 评论 0原文

我想在不从后端更改有效载荷的情况下更改推送通知的一些参数。

因此,该应用会收到推送通知:

{
    "Simulator Target Bundle": "com.test.iphone.driver.test",
    "aps":{
        "alert":"This is Alert.",
        "sound":"default"
    }
}

但是在执行通知之前,我需要将代码中的声音更改为“ custom.mp3”。 应该在这种方法中完成:在调用完成处理程序之前将提供通知

func userNotificationCenter( _ center: UNUserNotificationCenter,
        willPresent notification: UNNotification,
        withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void
      ) {
       completionHandler([.banner, .sound]) 
}

吗?

I would like to change some parameters of Push Notification without changing payload from backend side.

So the app receives a push notification:

{
    "Simulator Target Bundle": "com.test.iphone.driver.test",
    "aps":{
        "alert":"This is Alert.",
        "sound":"default"
    }
}

But I need to change sound in code to "custom.mp3" before performing notification.
It should be done in this method: willPresent notification before calling completion handler

func userNotificationCenter( _ center: UNUserNotificationCenter,
        willPresent notification: UNNotification,
        withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void
      ) {
       completionHandler([.banner, .sound]) 
}

Is it possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文