Eine Benachrichtigung wird angezeigt, aber beim Klicken auf diese Schaltfläche wird die Anwendung nur erneut geöffnet. Was ich möchte, ist beim Klicken auf die Benachrichtigung, öffnet es einen bestimmten Artikel.Ionic 2: Push-Benachrichtigung bei Klick
In Laravel, ich bin mit dem brozot/Laravel-FCM Paket für Firebase Cloud Messaging (FCM) Benachrichtigungen zu senden, und am anderen Ende, ich bin mit Ionic push notifications Benachrichtigungen in dem Infobereich zu empfangen und anzuzeigen.
Wenn ich auf Laravel setClickAction()
nicht verwende, wird die Ionic-Anwendung beim Klicken auf die Benachrichtigung geöffnet, aber wenn ich setClickAction()
einstelle, passiert nichts. Die Benachrichtigung verschwindet einfach.
Laravel-Code:
$notificationBuilder = new PayloadNotificationBuilder('my title');
$notificationBuilder->setBody('Hello world')
->setSound('default')
->setClickAction('window.doSomething');
$notification = $notificationBuilder->build();
Ionic 2 Rahmen Probe:
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');
}
Was bin ich?
ich implementiert das gleiche Funktionalität in Ionic mit One-Signal und Firebase (beide sind frei). Wenn Sie bereit sind, Plugin zu ändern, wird es als Antwort zur Verfügung stellen – Webruster
Ja, bitte, ich bin bereit – MTA
Bitte überprüfen Sie meine Lösung – Webruster