[英]Amazon Pinpoint and Ionic - Push notifications not working when app is in background
I was asked to develop a sample app integrated with Amazon Pinpoint.我被要求开发一个与 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 .唯一的区别是,我没有使用模拟器,而是在自己的手机(小米红米 4x)中执行项目,而不是GCM ,我使用了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.另外,如果有人知道代码的哪一部分负责此通知,请警告我,然后我将其上传到此处。
Okay, so after some tests I made it work (not through console, but through CLI).好的,经过一些测试,我让它工作了(不是通过控制台,而是通过 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.为此,我遵循了一些发现这个问题的步骤,这将我带到了另外两个文档: 一个来自亚马逊的教学如何通过 CLI 发送推送通知和一个简单但非常详细的 phonegap-plugin 教程,我们的 Ionic 中使用的插件应用程序来处理推送。
First of all, replace the phonegap-plugin in your app with the master version avaliable in the github link I sent you .首先,将您应用中的 phonegap-plugin 替换为我发送给您的 github 链接中提供的主版本。
Then, putting all those information together, I figured out how to write a .json file containing the information we need to send the pushes.然后,将所有这些信息放在一起,我想出了如何编写一个 .json 文件,其中包含我们发送推送所需的信息。 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 }]}}"
}
}
}
}
As you can see, to change the content in the push notificationm, you'll have to edit it's "RawContent" .如您所见,要更改推送通知中的内容,您必须编辑它的"RawContent" 。 To do so, use the phonegap-plugin tutorial I sent you and find out how to do the alterations you wish.为此,请使用我发送给您的 phonegap-plugin 教程,并了解如何进行您希望的更改。
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:最后一步:一旦您更新了插件版本并将上面的代码保存在.json文件中(我们称之为 test.json),您就可以将其发送到包含 .json 的文件夹中的手机打开命令行并写入:
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!如果有任何疑问,请告诉我!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.