Amazon Pinpoint和Ionic - 当应用程序处于后台时,推送通知不起作用 [英] Amazon Pinpoint and Ionic - Push notifications not working when app is in background

查看:182
本文介绍了Amazon Pinpoint和Ionic - 当应用程序处于后台时,推送通知不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被要求开发一个与Amazon Pinpoint集成的示例应用程序。由于我不是开发应用程序的专家,我决定遵循这个简单教程并按照其中描述的步骤开发应用程序。唯一的区别是,我没有使用模拟器,而是在我自己的手机(小米Redmi 4x)中执行项目,而不是 GCM ,我使用了 Firebase

I was asked to develop a sample app integrated with Amazon Pinpoint. Since I am not a pro at developing apps, I decided to follow this simple tutorial and develop the app following the steps described in it. The only differences are that, instead of using an emulator, I executed the project in my own cell phone (a Xiaomi Redmi 4x) and instead of GCM, I used Firebase.

起初,它似乎完美无缺,但当我将应用程序移至后台并返回主屏幕时,我再也无法接收来自应用程序的推送通知。当应用程序打开并运行时,每次发送推送通知时,都会出现一个弹出窗口,标题为新通知,按钮为忽略/查看。但是在后台时,我的系统托盘中看不到任何内容!

At first, it seemed to work perfectly, but when I moved the app to the background and went back to my homescreen, I could no more receive push notifications from my app. When the app is open and running, everytime I send a push notification a pop-up appears with Title "New Notification" and buttons "Ignore"/"View". But when in background, nothing is visible in my system tray!

此外,如果有人知道代码的哪一部分负责此通知,请警告我并上传它在这里。

Also, if someone knows which part of the code is responsible for this notifications, just warn me and I upload it here.

推荐答案

好的,经过一些测试后我才开始工作(不是通过控制台,而是通过CLI)。为此,我按照我发现的一些步骤这个问题,这带我去了另外两个文件:来自亚马逊的教授如何通过CLI发送推送通知一个简单但非常详细的phonegap-plugin教程,这个插件用于我们的Io​​nic应用程序来处理推送。

Okay, so after some tests I made it work (not through console, but through CLI). To do so, I followed some steps I found this question, that took me to two other documents: one from Amazon teaching how to send push notifications through CLI and a simple but very detailed tutorial of phonegap-plugin, the plugin used in our Ionic application to process the pushes.

首先,用您发送给我的github链接中的主版本替换应用中的phonegap-plugin

然后,将所有这些信息放在一起,我想出了如何编写包含发送推送所需信息的.json文件。以下是我使用的代码示例:

Then, putting all those information together, I figured out how to write a .json file containing the information we need to send the pushes. Here is a sample of the code I used:

{"MessageRequest": {
 "Addresses": {
 "YOUR_DEVICE_ADDRESS_HERE": {
 "ChannelType": "GCM"
 }
 },
 "MessageConfiguration": {
 "GCMMessage": {
 "RawContent":
"{\"data\":{\"title\":\"StackOverflow rocks!\",\"body\":\"Am I right?\",\"actions\":[ { \"title\":\"Yes!\", \"callback\":\"app.yes\", \"foreground\":true }, { \"title\":\"No!\", \"callback\":\"app.no\", \"foreground\":false }]}}"
 }
 }
}
}

如您所见,要更改推送通知中的内容,您必须编辑RawContent。为此,请使用我发送给您的phonegap-plugin教程,了解如何进行所需的更改。

As you can see, to change the content in the push notificationm, you'll have to edit it's "RawContent". To do so, use the phonegap-plugin tutorial I sent you and find out how to do the alterations you wish.

最后一步:更新插件后版本并将上面的代码保存在.json文件中(让我们称之为test.json),您可以将它发送到包含您的.json和写入的文件夹中的手机操作命令行:

Last step: once you updated your plugin version AND saved the code above in a .json file (let's call it test.json), you can send it to your phone oppening command line in the folder containing your .json and writting:

aws pinpoint send-messages --color on --region YOUR_SERVICE_REGION --cli-input-json file:///test.json

这应该可以解决问题!希望对你有效。如果有任何疑问,请告诉我!

This should do the trick! Hope it works for you. If any doubts, just let me know!

这篇关于Amazon Pinpoint和Ionic - 当应用程序处于后台时,推送通知不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆