在显示之前操作推送通知 (APNS)

Manipulate Push Notifications before showing (APNS)

早上好!

我有一个简单的问题:我可以在显示客户端之前操作 UIUserNotificationType.alert 消息吗?

例如,我可以在消息的索引 0 处添加一个“1:”吗?

这只是一个例子,我想在向他们展示客户端之前解密一条消息。有没有办法像 android?

直到现在我只有这个片段 - 但它只将通知注册为类型,我无法更改警报消息:

let notificationTypes: UIUserNotificationType = [UIUserNotificationType.alert, UIUserNotificationType.badge, UIUserNotificationType.sound]
let pushNotificationSettings = UIUserNotificationSettings(types: notificationTypes, categories: nil)

application.registerUserNotificationSettings(pushNotificationSettings)
application.registerForRemoteNotifications()

谢谢!

无法操作推送通知,因为它由 apple 处理。也可以秀苹果官方link

如果您想修改推送通知,那么您别无选择。您必须实施 Apple Push Kit。

1) Apple push Kit

Push Kit 框架为您的 iOS 应用程序提供 类 以接收来自远程服务器的推送。推送可以是两种类型之一:标准和 VoIP。标准推送可以发送通知,就像 iOS 的以前版本一样。 VoIP 推送在标准推送之上提供附加功能,VoIP 应用程序需要在向用户显示通知之前执行推送的按需处理。

所有知名的 VOIP 应用程序都使用 Apple push Kit 进行通知,例如 Whats App、Skype、Facebook Messenger。

使用通知服务应用程序扩展在将远程通知传递给用户之前修改其负载。 https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/ModifyingNotifications.html