PhoneGap的:"而processMessage失败"无法发送javascript函数(科尔多瓦2.5.0) [英] Phonegap: "processMessage failed" unable to send javascript function (Cordova 2.5.0)

查看:317
本文介绍了PhoneGap的:"而processMessage失败"无法发送javascript函数(科尔多瓦2.5.0)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让GCM推送通知我的应用程序工作,所以我使用这个项目(的https: //github.com/marknutter/GCM-Cordova )为例。

I am trying to make GCM push notifications work in my app and therefore I am using this project (https://github.com/marknutter/GCM-Cordova) as an example.

当我运行示例code一切工作正常,但是当我转移所有必需的文件和编辑我的code让它在自己的应用程序工作,它不工作了。
我也试过以下插件( https://github.com/phonegap-build/PushPlugin )并自动安装它后,它给完全相同的错误。

When I run the example code everything works fine, but when I transfer all the required files and edit my code to let it work in my own app it does not work anymore. I also tried the following plugin (https://github.com/phonegap-build/PushPlugin) and after installing it automatically it gives exactly the same error.

该应用程序不会崩溃,但是当我打电话的寄存器功能我的回调函数onNotificationGCM没有收到任何消息了。

The app does not crash, but when I call the register function my callback function "onNotificationGCM" does not receive any messages back.

注册功能:

window.plugins.GCM.register("my_gcm_id", "onNotificationGCM", successHandler, errorHandler );

一些调试我想通了,原生的Andr​​oid code是能够注册电话,确实得到从GCM服务器的ID信息,但是它不能发送这我的JavaScript后。

After some debugging I figured out that the native android code is able to register the phone and does indeed get an ID message from the GCM server, but that it is unable to send this to my javascript.

原生Android code:

public static void sendJavascript( JSONObject _json )
{
  String _d =  "javascript:"+gECB+"(" + _json.toString() + ")";
      Log.v(ME + ":sendJavascript", _d);

      if (gECB != null ) {
        gwebView.sendJavascript( _d );
      }
}

LogCat中给出了如下的失败的消息:

03-24 17:05:21.844: V/GCMPlugin:sendJavascript(31782): javascript:onNotificationGCM({"regid":"APA91bHX...31ASD","event":"registered"})

03-24 17:05:22.834: D/CordovaLog(31782): processMessage failed: Message: Jjavascript:onNotificationGCM({"regid":"APA91bHX...31ASD","event":"registered"})

资本的Ĵ在消息的前面很奇怪,也许这是什么原因造成的问题,但它似乎是在科尔多瓦2.5.0 code某处发生的事情。

The capital J in front of the message is strange and maybe that is what causes the problem, but it seems to be happening somewhere in the Cordova 2.5.0 code.

没有人有任何想法,我怎么能解决这个问题?

Does anyone have any idea how I can solve this?

推荐答案

尝试添加

window.onNotificationGCM = onNotificationGCM;

要改变你的函数的上下文

to change the context of your function

它解决的问题,我

这篇关于PhoneGap的:"而processMessage失败"无法发送javascript函数(科尔多瓦2.5.0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆