【问题标题】:Changing the contents of a pushed notification更改推送通知的内容
【发布时间】:2021-03-29 02:31:08
【问题描述】:
我想在接收推送通知的委托方法中更改与用户一起发送的 pushNotification 的内容(我正在使用 Firebase FCM)
我的计划是更改存储在 userInfo [AnyHashable:Any] 类型中的标题和正文值,并将 userInfo 设置为这个修改后的值。
根据Apple's documentation,它说 userInfo 是一个只能获取的属性。
我有什么办法可以更改客户端上 userInfo 的值吗?谢谢。
【问题讨论】:
标签:
json
swift
firebase-cloud-messaging
unusernotificationcenter
【解决方案2】:
我不确定如何更改通知中的用户信息,但您可以通过创建 NotificationServiceExtension 来更改推送通知内容。
请参阅此document。这是关于通过 firebase 通知发送图像。
但这会改变通知的内容。
// Modify the notification content here as you wish
self.bestAttemptContent.title = [NSString stringWithFormat:@"%@ [modified]",
self.bestAttemptContent.title];
【讨论】:
-
感谢您的回答!我已经实现了这个扩展,并且会另外推荐this video 来掌握如何实现它,并确保在你的设备通知中使用mutable_contents:1。