プッシュ通知に関するIonic 3の文書の指示に従っています。ionic 3とFirebase Cloud Messagingを使用して通知バーから特定のページを開くにはどうすればいいですか?
通知と私のアプリをバックグラウンドで送信しようとすると、「通知」イベントがトリガーされず、特定のページを通過できません。
私のアプリがフォアグラウンドになっているとき、「通知」イベントが自動的にトリガされました。
私が使用:
イオン3モバイルフレームワークとして
FirebaseクラウドMessaginsメッセージサービス
Laravelとしてlarave-FCMプラグインを使用してメッセージ
バックエンド - プッシュメッセージのLaravelコードfirebase
$optionBuilder = new OptionsBuilder();
$optionBuilder->setTimeToLive(60*20)->setContentAvailable(true);
$notificationBuilder = new PayloadNotificationBuilder('Hello');
$notificationBuilder->setBody('Hello world')->setSound('default');
$dataBuilder = new PayloadDataBuilder();
$dataBuilder->addData(['custom' => 'test']);
$option = $optionBuilder->build();
$notification = $notificationBuilder->build();
$data = $dataBuilder->build();
$token = "token";
$downstreamResponse = FCM::sendTo($token, $option, $notification, $data);
$success = $downstreamResponse->numberSuccess();
$failure = $downstreamResponse->numberFailure();
$modification = $downstreamResponse->numberModification();
echo 'Success: '.$success;
echo "<br>";
echo 'Failure: '. $failure;
echo "<br>";
echo 'Modification: '.$modification;
print_r($downstreamResponse->tokensToDelete());
echo "<br>";
print_r($downstreamResponse->tokensToModify());
echo "<br>";
print_r($downstreamResponse->tokensToRetry());
echo "<br>";
print_r($downstreamResponse->tokensWithError());
FRONTEND - app.component.ts
constructor(private translate: TranslateService, private platform: Platform, settings: Settings, private config: Config, private statusBar: StatusBar, private splashScreen: SplashScreen, public push: Push, public alertCtrl: AlertController, public storage: Storage, private backgroundMode: BackgroundMode) {
this.initTranslate();
this.platform.ready().then(() => {
if(!this.backgroundMode.isActive) {
this.backgroundMode.setDefaults({silent: true});
this.backgroundMode.enable();
} else {
this.backgroundMode.disable();
this.backgroundMode.setDefaults({silent: true});
this.backgroundMode.enable();
}
this.pushSetup();
this.storage.get('test').then((val) => {
if(val == 'news'){
this.nav.setRoot(TabsPage);
}
});
});
}
機能pushSetup()
pushSetup() {
const options: PushOptions = {
android: {
senderID: '10524067XXXXX'
},
ios: {
alert: 'true',
badge: true,
sound: 'false'
},
windows: {}
};
const pushObject: PushObject = this.push.init(options);
pushObject.on('notification').subscribe((notification: any) => {
if(notification.additionalData.foreground){
let myAlert = this.alertCtrl.create({
title: 'Push',
message: JSON.stringify(notification)
});
myAlert.present();
} else {
this.storage.set('test', 'news');
}
});
pushObject.on('registration').subscribe((registration: any) => {
console.log(registration);
});
pushObject.on('error').subscribe(error => console.error('Error with Push plugin', error));
}
編集:追加コード – Sandy
SOのような公開サイトにAPIトークンを入れないでください。 –
こんにちは、ありがとうございます!私は私のトークンを隠すことを忘れました:) – Sandy