为什么IONIC推送通知看起来像Javascript警报?
问题描述:
我成功地能够使用IONIC框架发送推送通知。但是这些通知看起来并不像我收到其他android通知,而是它们看起来像正常的Javascript警报。为什么IONIC推送通知看起来像Javascript警报?
是否有任何设置来设置推送通知类型像(警报或别的东西)?
我经历以下链接:https://devdactic.com/ionic-push-notifications-guide/
如果有人面对和解决这一点,那么请评论。
- 第一张截图显示了推送通知,如JavaScript警报。
- Second screenshot在锁定手机屏幕后显示默认Android通知。
- 第三截图显示解锁屏幕
答
我在我的app.js文件,该文件显示了onNotification事件通知,如果onNotification不存在,则离子显示默认将下面的代码到$ ionicPlatform.ready解决了这个问题Javascript警报。
var push = new Ionic.Push({
onNotification: function(notification) {
var payload = notification.payload;
console.log(notification, payload);
},
pluginConfig: {
ios: {
alert: true,
badge: true,
sound: true
},
android: {
sound: true,
vibrate: true,
forceShow: true,
iconColor: "#601dc2"
},
}
});
答
后默认的Android通知虽然与推送通知的工作,你有两种可能性得到通知一个在没有在屏幕上的头ification盘,而你的应用程序在后台模式和二当你在前台模式下您的应用程序工作
第一种是像其他的通知显示,以通知您收到了通知与您的应用程序消息和标志你设置
但是对于其他通知它只是用它来获得任何你通过它的数据和消息,而现在其对你,你怎么想显示在应用程序中
你可以设置一个div并隐藏显示它,当通知显示时,设计和位置为哟ü喜欢或根据你的应用程序的主题
<script>
function devicePushNotification(data)
{
if (data.additionalData.foreground == true)
{
$("#setNotificationText").text(data.message);
$("#setNotificationText").css("display","block");
}
}
</script>
<div style="width:50%;margin: 0 auto;display:none" id="setNotificationText">
</div>
或者,你可以提醒你得到了你已通过像任何通知的消息,
<script>
function devicePushNotification(data)
{
if (data.additionalData.foreground == true)
{
alert(data.message);
}
}
</script>
所以,如果你得到通知成功,那么你只需要创建任何格式良好的容器来显示它。
希望这有助于你
大!你可以在这个答案中分享屏幕截图,这样我就可以了解通知的默认视图。 –
嗨Kiran,请检查,我已编辑的问题和应用上面的代码后添加Android通知的默认视图。 – Himanshu
@Himanshu我仍然收到像警报一样的信息。 –