Phonegap: “processMessage failed” unable to send javascript function (Cordova 2.5.0)

自作多情 提交于 2019-12-06 08:40:29

Try to add

window.onNotificationGCM = onNotificationGCM;

to change the context of your function

It solve the problem for me

I had the same problem. After some debugging as I understood I had an unwanted new line character "\n" at the end of my string that I wasn't responsible for and it seems that phone gap added the character. So what I did was to .replace("\n", "") the string on the Java part of the code.

String js = "javascript:displayTextMessage('" + date.toString() + " - " + msg.replace("\n", "") + "');" ; sendJavascript(js);

This is not an Cordova 2.5.0 Bug! If you copy and paste from the "CORDOVA_GCM_script.js" example, you will have something like this:

case 'registered':
    // the definition of the e variable is json return defined in GCMReceiver.java
    // In my case on registered I have EVENT and REGID defined
    gApp.gcmregid = e.regid;
    if ( gApp.gcmregid.length > 0 )
    {
      $("#app-status-ul").append('<li>REGISTERED -> REGID:' + e.regid + "</li>");


      // ==============================================================================
      // ==============================================================================
      // ==============================================================================
      //
      // This is where you would code to send the REGID to your server for this device
      //
      // ==============================================================================
      // ==============================================================================
      // ==============================================================================

    }

    break

Make sure the "gApp" Array and the "gcmregedit" variable is declared in your script, or just don't use them in your eventhandler. Otherwise you'll get an "processMessage failed"-Message because of the "undefined"-error occuring before.

Check your code for any incorrect JSON.parse's... these "illegal access" etc. error messages seem to be thrown when JSON.parse(not_a_json_string) happens.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!