简体   繁体   中英

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. 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.

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.

First of all, replace the phonegap-plugin in your app with the master version avaliable in the github link I sent you .

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 }]}}"
            }
        }
    }
}

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.

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM