Search code examples
angularjsgoogle-cloud-messagingpubnub

AngularJS and PubNub GCM Push Notifications


I've been trying to implement push notifications using PubNub and their AngularJS SDK. However, I am receiving the message on my device but not a push notification through GCM.

I have the code below:

PubNub.ngPublish({
                            channel: channel,
                            message: {
                                "pn_gcm": {
                                    "data": {
                                        "summary": "Game update 49ers touchdown",
                                        "teams": ["49ers", "raiders"],
                                        "score": [7, 0],
                                        "lastplay": "5yd run up the middle"
                                    }
                                }
                            }
                        });

I get the message successfully with all the data but no Push notification when the app is in the background or closed.

What am I doing wrong?

Thanks

Update:

I'm pasting this in the console:

{
"pn_gcm": {
        "data" : {
            "summary": "Game update 49ers touchdown",
            "teams" : ["49ers", "raiders"],
            "score" : [7, 0],
            "lastplay" : "5yd run up the middle"
        }
    }
}

Solution

  • Implementing push notifications has multiple parts. As it applies to pubnub:

    1. registering your API key in the console and enabling push notifications. This enables you publish push notifications from the pubnub API

    2. enable push notifications on the channels you intend to use for push notifications. This step will register your device with the pubnub mobile-gateway for push and associate the device with the channels you are using for push.

    3. Finally, you need to implement GCM in the app so that it knows what to do when it receives a push notification:

    https://developer.android.com/google/gcm/client.html