我正在使用native firebase插件的推送通知功能。
当前行为:
它与前景工作正常。但是当应用程序在后台时我尝试点击它显示的通知<form accept-charset="UTF-8" action="submit.php" method="POST" id="myForm">
<label for="FirstName">First Name *</label>
<input id="FirstName" name="FirstName" type="text" />
<label for="Email">Email *</label>
<input id="Email" name="Email" type="text" />
<div class="radio_form">
<input name="sel_schedule" type="radio" value="https://app.webinarjam.net/ew/auto-register?webicode=69bb17b947&memberid=39867&firstname=yourname&email=your@email.com&schedule=1" onclick="javascript:document.getElementById('next_url').href=this.value;" checked="checked">
<label>Schedule 1</label>
<input name="sel_schedule" type="radio" value="https://app.webinarjam.net/ew/auto-register?webicode=69bb17b947&memberid=39867&firstname=yourname&email=your@email.com&schedule=2" onclick="javascript:document.getElementById('next_url').href=this.value;">
<label>Schedule 2</label>
<input name="sel_schedule" type="radio" value="https://app.webinarjam.net/ew/auto-register?webicode=69bb17b947&memberid=39867&firstname=yourname&email=your@email.com&schedule=3" onclick="javascript:document.getElementById('next_url').href=this.value;">
<label>Schedule 3</label>
</div>
<div class="submit_form">
<a id="next_url" name="next_url" href="https://app.webinarjam.net/ew/auto-register?webicode=69bb17b947&memberid=39867&firstname=yourname&email=your@email.com&schedule=1" onclick="document.getElementById('myForm').submit();">Submit</a>
</div>
</form>
<script>
var getUrlParameter = function getUrlParameter(sParam) {
var sPageURL = decodeURIComponent(window.location.search.substring(1)),
sURLVariables = sPageURL.split('&'),
sParameterName,
i;
for (i = 0; i < sURLVariables.length; i++) {
sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] === sParam) {
return sParameterName[1] === undefined ? true : sParameterName[1];
}
}
};
var webid = getUrlParameter('webid');
var firstName = getUrlParameter('firstname');
var email = getUrlParameter('email');
var schedule = getUrlParameter('schedule');
document.getElementById("FirstName").value = firstName;
document.getElementById("Email").value = email;
</script>
。请看下面的视频。我在Anroid设备上测试了这个。
预期行为:
当我点按通知消息时,它应该打开应用并正确显示消息。
app.component.ts
undefined
的package.json
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();
}
答案 0 :(得分:3)
我建议改用cordova-plugin-firebase。您可以查看this repo以了解如何使用该插件。
请注意,如果应用程序在前台运行,或者在通知到达时应用程序已关闭,发送的通知内容将不相同。为了解决这个问题,在发送通知时,在高级选项部分添加title
和body
: