amazon-archives / aws-mobile-ionic-sample

It is a Ionic Sample App that displays how web developers can integrate their front end with AWS on the backend. The App interacts with AWS Cognito, API Gateway, Lambda and DynamoDB on the backend.
Other
83 stars 46 forks source link

Not receiving push notifications outside of the app #6

Open barryross opened 6 years ago

barryross commented 6 years ago

I have followed https://aws.amazon.com/blogs/mobile/push-notifications-with-ionic-and-amazon-pinpoint/ and am receiving in-app notifications when sending via "direct" in the AWS console, but when the app is in the background or closed, no notifications come through. Any ideas why?

lucaslc-sp commented 6 years ago

I have same problem. Any solution?

Linknpay commented 6 years ago

same problem here !

gthole commented 6 years ago

I also ran into this. It only appears to affect Android for me - iOS apps receive notifications while the app is in background mode no problem.

Anyone figure this out yet? Any insight would be definitely appreciated!

medbz commented 6 years ago

same problem here

Linknpay commented 6 years ago

We had the same problem and we solve it for android background mode. Solution:

  1. Do not use FCM, use GCM. So, install the ionic push plugin v1 not v2.
  2. Do not use "withBody" function when sending messages to Android, use "withRawContent" instead with a json object as showed in the java example below:

    JSONObject gcmMessage = new JSONObject();
        try {
            JSONObject data = new JSONObject();
            data.put("title", title);
            data.put("body", message);
            gcmMessage.put("data", data);
        } catch(JSONException e){
            LOGGER.error(e);
        }
    
        DirectMessageConfiguration directMessageConfiguration = new DirectMessageConfiguration()
                .withAPNSMessage(new APNSMessage().withTitle(title).withBody(message).withSound("default"))
                .withGCMMessage(new GCMMessage()
                        .withRawContent(gcmMessage.toString())
                        .withSound("default"));

Hope it helps !

gthole commented 6 years ago

Well hooray! That worked very nicely. Thanks so much!

I'm a bit distressed that this only buys us a year before GCM is phased out and FCM is the defacto push notification API, but I'll take it for now.

Thanks again for the magic spell.