且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Amazon Pinpoint和Ionic - 当应用程序处于后台时,推送通知不起作用

更新时间:2023-02-27 09:23:55

好的,经过一些测试后我才开始工作(不是通过控制台,而是通过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\":\"*** 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!