The community forums are in BETA and closed to the public.

Phonegap Android GCM Push Notification: Error: PnMessage is undefined

I am building chat application in phonegap using GCM and Pubnub. I referred this article

My browser console is showing PnMessage is undefined. I have checked in pubnub.js file. It is defined there. So what is the issue then? These are my files:-


<!DOCTYPE html>
    <title>Page Title</title>
    <script src="index.js"></script>
    <script src="pubnub-3.7.6.min.js"></script>

<body onload="onLoad()">
    <h1>This is a Heading</h1>  <p>This is a paragraph.</p>


var pubnub;
function onLoad(){
    pubnub = PUBNUB.init({ 
        subscribe_key: 'sub-c-2dc2f5b4-8d29-...........', 
        publish_key: 'pub-c-124ec6e8-c.......'

        channel: 'Doctor',
        message: {"message":"phonegap onDeviceReady"}


function  sendPush() { 
    pubnub.mobile_gw_provision ({ 
        device_id: 'APA91bFWRqK3ItjGduf3UZKbxbn_.........', // Reg ID you got on your device 
        channel : 'Doctor', 
        op: 'add', 
        gw_type: 'gcm', 
        error : function(msg){ console.log(msg); }, 
        callback : successCallback 

function  successCallback() { 

    var message = PnMessage();
    message.pubnub = pubnub; 
    message.callback = function(msg){ console.log(msg); }; 
    message.error = function (msg){ console.log(msg); }; = 'Doctor'; 

    message.gcm = { 
        title: 'Push Demo', 
        message: 'The room temperature is set too high' 


Got the issue solved. min version of pubnub.js doesn't has the PnMessage class. we have to use the bigger version of pubnub.js

Reformatted the code above as some was not displaying at all.

I'll have to verify but the sendPush method is just registering a device for push notification but you are calling pubnub.publish before this device is registered. Register the device first then publish - and make sure the device has completed registering before publish is called (async warning).

Yeah, my analysis didn't take into account your successCallback function. The minified version on cdn should have been updated by now. Your local copy could have just been a day or two out of date, maybe?

Either way, glad it is working for you know.

Thanks Craig for your answer. However we are still using original version of still doesn't has the PnMEssage class.

It's in there but it is spelled PNmessage but your code uses PnMessage (uppercase M). Give that a fix and let me know if you still have issues.

:( Not working. What I am doing: Taking a local copy of I have tried both PNmessage() and PnMessage(). Both are showing undefined in the web-app.

When I am trying to search for PNmessage in I only got one search result: newPnMessage:function.....

Forget 3.7.6. We just updated the CDNs with 3.7.8 that has all the latest from github repo.

Please use the following and let me know if you continue to have issues:

NOTE: versions updated to current latest (3.7.8) but always check for latest version on our JavaScript SDK github repo.

Login or Signup to post a comment