【问题标题】:Push Notification ios - Background and Kill State - React Native推送通知 ios - 背景和终止状态 - React Native
【发布时间】:2022-01-22 23:58:48
【问题描述】:

我在 react native 中使用了 PushNotification 库。我到达时在我的设备中使用数据对象 json 在前台接收通知有效负载。但是在终止模式下,当我使用 (notification.userInteraction) 单击通知时,收到的对象数据仅包含标题和声音名称。你能帮我获取数据对象吗其中包含(引用键和开始)并认为:)

 if (notification.userInteraction) {
    }

    if (notification.userInteraction) {
        // Handle notification click
       // alert('good');
        alert(JSON.stringify(notification));
        let notif=notification.data.aps.data;
        let id=notif.id;
       // alert("notificatin="+id);
      }  
    
    
    

酒吧

 {"pn_apns":{
          "aps":{
            "alert": {
                "body": "TEST",
                "title": "TEST1"
            },
    "sound": "beep.wav",
             
    "data": { "reference": "ND1004332", "startstation": "" }
              },
          "pn_push":[
             {
                "push_type":"alert",
                "auth_method":"token",
                "targets":[
                   {
                      "environment":"development",
                      "topic":"com.oui.fr"
                   }
                ],
                "version":"v2"
             }
          ]
    
    }
          
    }  


       

【问题讨论】:

  • 抱歉,我听不懂英文。您是说当应用程序处于前台时此有效负载被传递到您的应用程序,但是当应用程序被用户终止时,通知没有传递?就像你什么都没看到?
  • 我通过我的设备发送了通知 ios 它工作正常通知中收到的数据但是在终止模式下找不到或未收到数据
  • 我使用 notification.userInteraction 通过点击显示通知 json 对象
  • 1.你能显示有效载荷吗?你用你的编辑删除了它。 2. 显示您正在实现哪个委托回调的代码。 3. 还可以深入了解content-available,例如见herehere
  • 4.有关一般提示,请参阅 herehere

标签: ios react-native push-notification


【解决方案1】:

我通过更改pubnub中json的结构并添加content_available键来解决它。

 {"pn_apns":{
          "aps":{
            "alert": {
                "body": "TEST",
                "title": "TEST1"
            },
    "sound": "beep.wav
              },
",
             
    "data": { "reference": "ND1004332", "startstation": "" },
   "content_available" : "1",
          "pn_push":[
             {
                "push_type":"alert",
                "auth_method":"token",
                "targets":[
                   {
                      "environment":"development",
                      "topic":"com.oui.fr"
                   }
                ],
                "version":"v2"
             }
          ]
    
    }
          
    }  

【讨论】:

    猜你喜欢
    • 2021-09-19
    • 2019-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-17
    • 1970-01-01
    相关资源
    最近更新 更多