【问题标题】:ionic 3 with FCM push notifications not working on Android device带有 FCM 推送通知的 ionic 3 无法在 Android 设备上运行
【发布时间】:2018-05-19 18:45:00
【问题描述】:

我一直在尝试从 PostMan 或 CURL PHP 脚本向我的 Android 设备发送推送通知,但我没有收到消息。如果我从 Firebase 控制台发送通知,通知它有效,我收到推送通知。这是我在 app.component.ts 上的代码:

import { Component, ViewChild } from '@angular/core';
import { Nav, Platform, AlertController } from 'ionic-angular';
import { HomePage } from '../pages/home/home';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import {FCM, NotificationData} from "@ionic-native/fcm";
@Component({
  templateUrl: 'app.html',
  providers: [Services]
})
export class MyApp {
 @ViewChild(Nav) nav: Nav;
 rootPage:any;
 pages: Array<{title: string, component: any, icono: any}>;

 constructor(public platform: Platform, public alertCtrl: 
 AlertController, public statusBar: StatusBar, public splashScreen: 
 SplashScreen, private fcm: FCM ) {
  this.initializeApp();

  }

 initializeApp() {
 this.platform.ready().then(() => {
  this.statusBar.styleDefault();
  this.splashScreen.hide();

   this.fcm.getToken()
    .then((token:string)=>{
     console.log("The token to use is: ",token);
    })
    .catch(error=>{
      console.error(error);
    });


  this.fcm.onTokenRefresh().subscribe(
    (token:string)=>console.log("Nuevo token",token),
    error=>console.error(error)
  );


  this.fcm.onNotification().subscribe(
    (data:NotificationData)=>{
      if(data.wasTapped){
        console.log("Received in background",JSON.stringify(data));
      }else{

        console.log("Received in foreground",JSON.stringify(data))
      }
     },error=>{
      console.error("Error in notification",error)
     }
  );

});

这是我的邮递员 POST : HEADER :

这是我的信息:

这是回应:

如您所见,我收到了成功:1 -> 这意味着通知已发送,但在我的 Android 设备中从未收到。

有人有同样的问题吗? 正如我之前所说,我正在从 firebase 控制台收到通知。 在此先感谢您的任何 cmets。

【问题讨论】:

  • 嗨 CaribeSoft,你解决了吗,我也遇到了同样的问题
  • 嗨,Udit,尚未解决。
  • 我已经搞定了
  • 其实postman我没试过……直接写PHP代码就行了
  • 你能发布你的代码吗?

标签: firebase firebase-cloud-messaging ionic3 cordova-plugin-fcm


【解决方案1】:

试试这个负载:

 {
    "notification":{
      "title":"Title1", 
      "body": "Body1",  
      "sound": "default"
    },
    "data":{
      "param1":"param1",  
      "param2": "param2"
    },
    "to":"*Token*", 
    "priority":"high"
  }

【讨论】:

    【解决方案2】:

    请试试这个背景

     {
       data: {
            title: title,
            body: body,
            "sound": "default",
            "content-available": "1",
            "click_action": "FCM_PLUGIN_ACTIVITY"
        },
        tokens: Tokens
    }
    

    或者您可以尝试前台数据和通知键

    {
       notification: {
            title: title,
            body: body,
            "sound": "default",
            "content-available": "1",
            "click_action": "FCM_PLUGIN_ACTIVITY"
        },
        tokens: Tokens
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-07-06
      • 2017-04-27
      • 2017-06-13
      • 1970-01-01
      • 1970-01-01
      • 2020-09-14
      • 1970-01-01
      相关资源
      最近更新 更多