gpt4 book ai didi

ios - 推送通知正在接收,但在发送 PubNub 聊天消息有效负载时,后台提取不使用 pn_apns 标记调用

转载 作者:可可西里 更新时间:2023-11-01 01:49:41 25 4
gpt4 key购买 nike

我使用 PubNub 服务而不是 PubNub 聊天引擎在我的应用程序中设置了一个聊天模块。一切正常,直到出现推送通知。此应用程序也有 Android 版本(不是我构建的)。我能够使用下面提到的 payload1 接收功能齐全的 Apple 推送通知。但就通知而言,它仅适用于 iOS 设备,对于为通知添加了 GCM 的 Android 设备没有通知。

所以我做了一些 RND 并找到了这个 Link并使用了下面提到的 Payload2。使用这两个平台都会收到通知。但现在在 iOS 中,通知同时出现在前台和后台应用程序状态上。但是下面提到的所有方法都没有调用,现在唯一调用的方法是前台的willPresent。我想知道为什么会这样。有效载荷或标签有问题还是什么?请帮助我为此奋斗了一个星期。提前致谢。

payload1 = [
"aps" : [
"alert" : [
"title" : self.loginUserProfile.firstName,
"body" : message],
"pn_exceptions" : [
tokenString
],
"content-available": 1,
"sound" : "marco_alert.aiff",
"publisher" : self.loginUserProfile.userId,
"date" : Date().dateString()]
] as [String : Any]
payload2 = [
"pn_apns":
[
"date": Date().dateString(),
"aps":
[
"sound": "marco_alert.aiff",
"alert":
[
"title": self.loginUserProfile.firstName,
"body": message
],
],
"pn_exceptions": [tokenString],
"publisher": self.loginUserProfile.userId,
"content-available": 0
],
"pn_gcm": [
"data": messageString
]] as [String : Any]

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void)

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) 

func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void)```

最佳答案

@Ahsan 我想确保我理解您描述的行为:当应用程序处于后台时,使用上述有效负载通过 PubNub 发送的通知在 Android 和 iOS 上工作。但是当 iOS 应用程序在前台时,通知只调用 func userNotificationCenter(_ center: UNUserNotificationCenter,
willPresent通知:UNNotification,
withCompletionHandler 完成处理程序:
@escaping (UNNotificationPresentationOptions) -> Void)
?

如果是这样,这就是官方 Apple iOS 文档中描述的 Apple iOS 推送通知行为。从历史上看,推送通知旨在用于应用程序活跃使用之外的操作,因此此记录的方法作为更新的机制提供,以便在应用程序处于事件状态时与推送通知进行交互。

Apple has a diagram here explaining how to respond to this delegate method and cause the notification to present to the user.

您可能还想查看 UNNotificationPresentationOptions as well for the available choices here.

关于ios - 推送通知正在接收,但在发送 PubNub 聊天消息有效负载时,后台提取不使用 pn_apns 标记调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55411318/

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