通知未显示在我的设备离子3中
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了通知未显示在我的设备离子3中相关的知识,希望对你有一定的参考价值。
我已经使用“cordova插件添加cordova-plugin-fcm”在设备上显示通知。我正在使用Ionic 3.我被卡住了请帮我解决这个问题
我的代码app.componet.ts
import { Component } from '@angular/core';
import {Platform} from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { Push, PushObject, PushOptions } from '@ionic-native/push';
//storage
import { Storage } from '@ionic/storage';
import {HomePage} from "../pages/home/home";
import {LoginnewPage} from "../pages/loginnew/loginnew";
import {FCM} from "@ionic-native/fcm";
@Component({
templateUrl: 'app.html'
})
export class MyApp {
rootPage:any;
constructor(private fcm:FCM,private push:Push,private storage: Storage,platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen) {
platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
this.fcm.subscribeToTopic('all');
this.fcm.getToken().then(token=>{
console.log("FCM Token");
console.log(token);
});
this.fcm.onNotification().subscribe(data=>{
if(data.wasTapped){
console.log("Received in background");
} else {
console.log("Received in foreground");
};
});
this.fcm.onTokenRefresh().subscribe(token=>{
console.log(token);
});
statusBar.styleDefault();
splashScreen.hide();
// console.log("pushsetup start");
//this.pushsetup()
});
storage.get('token').then((val) => {
console.log('Your Token is', val);
if(val === null || val === "non")
{
this.rootPage = LoginnewPage;
}else
{
this.rootPage=HomePage;
}
});
}
}
如何在我的移动设备上显示通知?如何获取令牌并发送服务器api端?
答案
- 要将令牌发送到您的后端,您必须在此函数内执行此操作:
this.fcm.getToken().then(token=>{
console.log("FCM Token");
console.log(token);
// put your backend api call here:
this.yourProvider.sendTokenToServer(token)
});
以上是关于通知未显示在我的设备离子3中的主要内容,如果未能解决你的问题,请参考以下文章