通知出現,但點擊它們後,只會再次打開應用程序。我想要的是點擊通知後,它會打開一個特定項目。離子2:點擊時發送推送通知
在Laravel中,我使用用於Firebase雲消息傳遞(FCM)的brozot/Laravel-FCM包發送通知,另一方面,我使用Ionic push notifications在通知托盤中接收和顯示通知。
如果我在Laravel上沒有使用setClickAction()
,則Ionic應用程序會在單擊通知後打開,但如果我設置了setClickAction()
,則不會發生任何情況。通知僅僅消失。
Laravel代碼:
$notificationBuilder = new PayloadNotificationBuilder('my title');
$notificationBuilder->setBody('Hello world')
->setSound('default')
->setClickAction('window.doSomething');
$notification = $notificationBuilder->build();
離子2框架樣品:
import { Component, ViewChild } from '@angular/core';
import { Platform, Nav, MenuController, ModalController, Events, AlertController } 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';
import { Storage } from '@ionic/storage';
import {
SearchPage
} from '../pages/pages';
@Component({
templateUrl: 'app.html'
})
export class MyApp {
@ViewChild(Nav) nav: Nav;
rootPage: any = SearchPage;
constructor(
platform: Platform,
statusBar: StatusBar,
splashScreen: SplashScreen,
private menu: MenuController,
private modalCtrl: ModalController,
private events: Events,
private push: Push,
private alertCtrl: AlertController,
private storage: Storage
) {
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.
statusBar.styleDefault();
splashScreen.hide();
});
this.pushSetup();
}
pushSetup() {
const options: PushOptions = {
android: {
senderID: 'xxxxxxxxxxx',
forceShow: true
},
ios: {
senderID: 'xxxxxxxxxxx',
alert: 'true',
badge: true,
sound: 'true'
},
windows: {},
browser: {
pushServiceURL: 'http://push.api.phonegap.com/v1/push'
}
};
const pushObject: PushObject = this.push.init(options);
pushObject.on('notification').subscribe((notification: any) => {
});
pushObject.on('registration').subscribe((registration: any) => {
alert(registration.id);
});
pushObject.on('error').subscribe(error => alert('Error with Push plugin' + error));
}
}
(<any>window).doSomething = function() {
alert('doSomething called');
}
我缺少什麼?
我實施了同樣的Ionic的One-Signal和Firebase功能(都是免費的)。如果你願意改變插件將它作爲答案 – Webruster
是的,我願意 – MTA
請檢查我的解決方案 – Webruster