未获得有关 cordova 推送通知的完整信息 (cordova-plugin-firebasex)

     2023-03-16     95

关键词:

【中文标题】未获得有关 cordova 推送通知的完整信息 (cordova-plugin-firebasex)【英文标题】:Not getting complete information on push notification on cordova (cordova-plugin-firebasex) 【发布时间】:2021-08-01 20:44:43 【问题描述】:

我正在开发一个需要推送通知的 Cordova 应用程序。对于推送通知,我使用了 cordova-plugin-firebasex 插件。它在应用程序处于前台时运行良好,但当应用程序处于后台时,通知栏上会显示推送通知,但当我点击它时,它不会显示标题、正文和其他数据。目前它显示以下消息:

collapse_key: "com.hadi.storex"  
from: "383656394813"  
google.delivered_priority: "normal"  
google.message_id: "0:1620737447755747%7dc0077a7dc0077a"   
google.original_priority: "normal"   
google.sent_time: 1620737447734   
google.ttl: 2419200   
messageType: "notification"   
tap: "background"   

我的 js 代码如下:

-

   function onDeviceReady() 
          FirebasePlugin.getToken(function (fcmToken) 
          console.log(fcmToken);    , function (error) 
          console.error(error);    );    FirebasePlugin.onTokenRefresh(function (fcmToken) 
          console.log(fcmToken);    , function (error) 
          console.error(error);    );    FirebasePlugin.onMessageReceived(function (message) 
          console.log("Message type: " + message.messageType);
          if (message.messageType === "notification") 
              console.log("Notification message received");
              if (message.tap) 
                  console.log("Tapped in " + message.tap);
              
          
          console.dir(message);
         , function (error) 
             console.error(error);
         );    
       document.addEventListener("deviceready", onDeviceReady, false);

我的 PHP 代码如下:

-

$path_to_fcm = "https://fcm.googleapis.com/fcm/send";   
       $headers = array(    
          'Authorization:key=' . FCM_SERVER_KEY,    
          'Content-Type:application/json');     
   
   $fields = array(

       "to" => 'registration_ids',

       'notification' => array(
           'title' => "title of notification1122",
           'body' => "your notification goes here22233",
           "surveyID" => "ewtawgreg-gragrag-rgarhthgbad",
           "data" => array(
               'title' => "title of notification1122",
               'body' => "your notification goes here22233",
               "notification_body" => "Notification body",
               "notification_title" => "Notification title",
               "surveyID" => "ewtawgreg-gragrag-rgarhthgbad"
           )
       )
   );

   $payload = json_encode($fields);


   $curl_session = curl_init();

   curl_setopt($curl_session, CURLOPT_URL, $path_to_fcm);
   curl_setopt($curl_session, CURLOPT_POST, true);
   curl_setopt($curl_session, CURLOPT_HTTPHEADER, $headers);
   curl_setopt($curl_session, enter code hereCURLOPT_RETURNTRANSFER, true);
   curl_setopt($curl_session, CURLOPT_SSL_VERIFYPEER, false);
   curl_setopt($curl_session, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
   curl_setopt($curl_session, CURLOPT_POSTFIELDS, $payload);

   $curl_result = curl_exec($curl_session);
   print_r($curl_result);

【问题讨论】:

【参考方案1】:

在fcm服务器上发送数据的正确方式是

$fields = 数组(

        'notification' => array(
            'title' => "title of notification1122",
            'body' => "your notification goes here22233",
            "sound" => "default",
            "click_action" => "FCM_PLUGIN_ACTIVITY",
            "icon" => "fcm_push_icon"
        ),
        "data" => array(
            "param1" => "value1",
            "param2" => "value2"
        ),
        "to" => any device device token or topic like "/topics/topicName" , 
        "priority" => "high",
        "restricted_package_name" => ""
    );

    $payload = json_encode($fields);

【讨论】:

如何在cordova上获得android原生推送通知?

】如何在cordova上获得android原生推送通知?【英文标题】:Howtogetandroidnativepushnotificationoncordova?【发布时间】:2015-12-1511:26:25【问题描述】:服务器发送通知时正在触发应用程序上的事件,但我只收到应用程序上消息的警报,而... 查看详情

Cordova 推送通知 (PhoneGap PushPlugin) 未触发 ecb 回调 (onNotificationAPN)

】Cordova推送通知(PhoneGapPushPlugin)未触发ecb回调(onNotificationAPN)【英文标题】:CordovaPushNotifications(PhoneGapPushPlugin)notfiringecbcallback(onNotificationAPN)【发布时间】:2014-04-0323:19:34【问题描述】:我将CordovaPushNotificationsPlugin1.3.4与我 查看详情

解析推送通知:iOS 设备令牌未定义

...【发布时间】:2015-06-0409:29:30【问题描述】:我正在使用Cordova(和IntelXDK)开发适用于iOS平台的应用程序。我正在使用此插件通过Parse平台推送通知:https://github.com/cranberrygame/cordova-plugin-pushno 查看详情

未发送有关可用应用更新的 Google Play 推送通知。我错过了啥吗?

】未发送有关可用应用更新的GooglePlay推送通知。我错过了啥吗?【英文标题】:GooglePlaypushnotificationforappupdateavailableisnotsent.AmImissingsomething?未发送有关可用应用更新的GooglePlay推送通知。我错过了什么吗?【发布时间】:2016-09-230... 查看详情

Cordova windows 8 手机 WNS 推送通知和应用发布流程及详细信息

】Cordovawindows8手机WNS推送通知和应用发布流程及详细信息【英文标题】:Cordovawindows8phoneWNSpushnotificationandappreleaseprocesswithdetails【发布时间】:2015-12-0411:43:20【问题描述】:我正在使用cordova开发windowsphone应用程序。我需要在这个... 查看详情

无法获得缺少的 gcm 推送通知

...1-1805:24:21【问题描述】:我正在将gcm推送通知从php发送到cordova应用程序。当用户移动连接到互联网时,它运行良好。如果用户手机在4小时内没有连接到互联网,并且在此期间我的服务器正在发送5个通知。在连接到互联网时,用... 查看详情

Firebase 网络推送通知令牌未获得

】Firebase网络推送通知令牌未获得【英文标题】:Firebasewebpushnotificationtokennotgetting【发布时间】:2019-03-1607:01:10【问题描述】:我是iOS开发人员而不是php,我正在实现Firebase网络推送通知以在网络中发送和接收。我正在使用xampp和... 查看详情

需要在 Cordova 应用程序中使用本机 APNs/GCM 为 iOS 推送通知的指导

】需要在Cordova应用程序中使用本机APNs/GCM为iOS推送通知的指导【英文标题】:NeedguidancetoPushNotificationforiOSusingNativeAPNs/GCMinCordovaApplication【发布时间】:2016-06-0809:27:17【问题描述】:我在我的cordova应用程序中使用了推送通知plugin... 查看详情

使用 Eclipse(推送插件)在 PhoneGAP 中推送通知:未获得注册 ID

】使用Eclipse(推送插件)在PhoneGAP中推送通知:未获得注册ID【英文标题】:PushNotificationinPhoneGAPusingEclipse(PushPlugin):Didn\'tgetRegistrationID【发布时间】:2014-07-1611:33:47【问题描述】:我正在使用Eclipse开发PhoneGAP,并实现了PushPluginhtt... 查看详情

phonegap build:在 iOS 9.1 推送通知上未获得注册 ID

】phonegapbuild:在iOS9.1推送通知上未获得注册ID【英文标题】:phonegapbuild:NotgettingregistrationIdoniOS9.1pushnotification【发布时间】:2015-11-1614:24:48【问题描述】:我正在尝试使用最新的推送通知插件构建一个简单的应用程序。我正在使... 查看详情

Cordova 推送通知操作

】Cordova推送通知操作【英文标题】:Cordovapushnotificationactions【发布时间】:2016-03-0322:51:22【问题描述】:Cordova当然有发送推送通知的选项,但是否有任何插件包含直接向通知添加操作的功能?我尝试搜索“交互式通知”和“通... 查看详情

如何使用 Quickblox 在 Cordova 应用程序中实现推送通知支持?

】如何使用Quickblox在Cordova应用程序中实现推送通知支持?【英文标题】:HowtoimplementpushnotificationsupportinCordovaappusingQuickblox?【发布时间】:2015-03-3113:34:49【问题描述】:对于这样一个基本问题,我深表歉意,但我真的找不到任何... 查看详情

iOS 应用未收到来自 Firebase 的后台推送通知

...2019-04-1902:41:26【问题描述】:我正在尝试在我正在开发的Cordova应用程序中使用推送通知。它们在Android应用中运行良好,在iOS应用处于前台时也运行良好,但是当应用处于后台或终止时我没有收到任何通知。我启用了“推 查看详情

Android 中的推送通知失败,并显示“未设置 GCM 的连接详细信息”

】Android中的推送通知失败,并显示“未设置GCM的连接详细信息”【英文标题】:PushnotificationinAndroidfailswith"connectivitydetailstoGCMarenotset"【发布时间】:2015-10-2810:21:43【问题描述】:我们正在运行MobileFirstPlatformFoundation7.0,... 查看详情

应用程序被杀死时未收到 IOS 13 VOIP 推送通知

...【发布时间】:2020-09-1917:58:04【问题描述】:我们有一个Cordova应用程序,它使用WebRTC进行视频聊天。我们正在使用这个插件来实现VOIP推送通知https://github.com/mattkhaw/cordova-plugin-callkit 查看详情

Cordova 中的后台 Firebase 推送通知

】Cordova中的后台Firebase推送通知【英文标题】:BackgroundFirebasePushNotificationsinCordova【发布时间】:2017-11-0605:01:12【问题描述】:我正在使用phonegap-plugin-push在Cordova应用程序中接收通知。我正在部署在androidMarsh-mellow上进行测试。我... 查看详情

是否有任何有效的 Cordova 推送通知? [关闭]

】是否有任何有效的Cordova推送通知?[关闭]【英文标题】:IsthereanyworkingCordovaPushNotification?[closed]【发布时间】:2016-11-0208:56:34【问题描述】:是否有任何可用的Cordova推送通知插件?这一项已被禁用:https://github.com/phonegap/phonegap-... 查看详情

Cordova 推送通知 - 注册标签

】Cordova推送通知-注册标签【英文标题】:CordovaPushNotification-RegisterTags【发布时间】:2017-04-1901:05:40【问题描述】:初次注册后如何注册额外的推送通知标签?以下代码成功注册标签(arrTags):pushRegistration.on(\'registration\',function... 查看详情