通知が表示されますが、クリックするとアプリケーションが再び開きます。私が望むのは、通知をクリックすると、特定のアイテムが開きます。イオン2:クリック時に通知をプッシュ
LaravelではFirebase Cloud Messaging(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');
}
私は何をしないのですか?
私は同じものを実装しましたOne-Signalとfirebaseを備えたIonicの機能(どちらも無料)です。プラグインを変更したい場合は、 – Webruster
のように回答してください。ありがとうございます。 – MTA
私の解決策を確認してください – Webruster