我正在使用native firebase插件的推送通知功能。推送通知不起作用背景
當前的行爲:
它與foreground.But工作正常時,應用程序在後臺,我要儘量挖掘它顯示undefined
。請看到視頻below.I已經測試了這個通知在Anroid設備上。
預期的行爲:
當我點擊通知消息應該打開的應用程序,並正確顯示該消息。
app.component.ts
constructor(public platform: Platform)
{
platform.ready().then(() => {
this.onNotificationOpen();
});
}
onNotificationOpen(): void {
if (this.platform.is('cordova')) {
this.firebase.onNotificationOpen()
.subscribe(res => {
if (res.tap) {//background mode
console.log(res.body);
this.showAlert(res.body);
} else if (!res.tap) {//foreground mode
console.log(res.body);
this.showAlert(res.body);
}
});
}
}
showAlert(message: string): void {
let alert = this.alertCtrl.create({
title: 'Push Notification',
subTitle: message,
buttons: ['OK']
});
alert.present();
}
的package.json
{
"name": "ionic-hello-world",
"author": "Ionic Framework",
"homepage": "http://ionicframework.com/",
"private": true,
"scripts": {
"clean": "ionic-app-scripts clean",
"build": "ionic-app-scripts build",
"ionic:build": "ionic-app-scripts build",
"ionic:serve": "ionic-app-scripts serve"
},
"dependencies": {
"@angular/common": "4.1.0",
"@angular/compiler": "4.1.0",
"@angular/compiler-cli": "4.1.0",
"@angular/core": "4.1.0",
"@angular/forms": "4.1.0",
"@angular/http": "4.1.0",
"@angular/platform-browser": "4.1.0",
"@angular/platform-browser-dynamic": "4.1.0",
"@ionic-native/core": "3.6.1",
"@ionic-native/device": "3.6.1",
"@ionic-native/facebook": "^3.10.0",
"@ionic-native/firebase": "^3.10.3",
"@ionic-native/keyboard": "^3.10.3",
"@ionic-native/splash-screen": "3.6.1",
"@ionic-native/status-bar": "3.6.1",
"@ionic/cli-plugin-cordova": "^1.2.0",
"@ionic/cli-plugin-ionic-angular": "^1.2.0",
"@ionic/storage": "2.0.1",
"@ngrx/core": "^1.2.0",
"@ngrx/store": "^2.2.1",
"d3": "^4.7.4",
"firebase": "^3.7.5",
"ionic-angular": "3.2.1",
"ionicons": "3.0.0",
"moment": "^2.18.1",
"pouchdb": "^6.1.2",
"pouchdb-adapter-cordova-sqlite": "^2.0.2",
"rxjs": "5.1.1",
"sw-toolbox": "3.6.0",
"zone.js": "0.8.10"
},
"devDependencies": {
"@ionic/app-scripts": "1.3.7",
"@ionic/cli-plugin-cordova": "1.2.1",
"@ionic/cli-plugin-ionic-angular": "1.2.0",
"typescript": "~2.2.1"
},
"cordovaPlugins": [
"cordova-plugin-whitelist",
"cordova-plugin-console",
"cordova-plugin-statusbar",
"cordova-plugin-device",
"cordova-plugin-splashscreen",
"ionic-plugin-keyboard"
],
"cordovaPlatforms": [
"ios",
{
"platform": "ios",
"version": "",
"locator": "ios"
}
],
"description": "helloWorld: An Ionic project"
}
你從火力控制檯發送推送通知?我沒有使用相同的插件,但請注意,當應用程序在後臺運行時(因爲標題和正文顯示在通知本身中),AFAIK firebase不會在通知中發送相同的數據。請看看[這個答案](https://stackoverflow.com/questions/43928185/how-to-read-firebase-push-notification-content-and-fire-a-method-in-ionic2/43950976# 43950976)(特別是它的最後一部分) – sebaferreras
哦....你太棒了。你可以把最後一部分放在Git repo鏈接嗎?謝謝@sebaferreras – Sampath
Np!我已經按要求添加了這些部分:) – sebaferreras