当应用程序没有运行GCM科尔多瓦推送通知无法正常工作 [英] GCM Cordova Push Notification not working when App not running

查看:143
本文介绍了当应用程序没有运行GCM科尔多瓦推送通知无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该应用程序是在PhoneGap的。我使用的推送通知功能与 https://github.com/marknutter/GCM-Cordova

The application is in PhoneGap. I am using push notification feature with https://github.com/marknutter/GCM-Cordova

我实现了全功能和它的工作很好,直到昨天。当我最后一天检查了应用,推动应用程序时没有运行通知不工作。所有的通知都接收设备上,点击邮件打开的应用程序。

I implemented the whole feature and it worked fine until yesterday. When I checked the app last day, push notification is not working when the app is not running. All notifications are receiving on my device, clicking on the message opens the app.

但控件没有收到在那里消息通知处理JavaScript的部分。

But the controls are not receiving at the javascript portion where message notification handles.

从文件GCMIntentService.java code:

Code from file GCMIntentService.java:

JSONObject json;
json = new JSONObject().put("event", "message");

json.put("message", extras.getString("message"));
json.put("link", extras.getString("link"));

Log.v(ME + ":onMessage ", json.toString());

GCMPlugin.sendJavascript( json );
// Send the MESSAGE to the Javascript application

这code将工作时收到的消息。但在那个时候,应用程序没有运行。

This code will work when the message received. But at that time, App is not running.

当我点击通知消息,该应用程序正常打开,没有登记的消息事件;从而没有得到控制的JavaScript来处理推送通知。

When I click on the notification message, the app opens as usual, not registering the message event; thereby not getting the control in JavaScript to handle push notification.

$ C $下CORDOVA_GCM_script.js,请访问:

Code for CORDOVA_GCM_script.js is available at:

https://github.com/marknutter/GCM-Cordova/blob/master/assets/www/CORDOVA_GCM_script.js

注意:它工作正常的应用程序运行时

Note: It works fine when the app is running.

编辑: 通知有时运行。 JavaScript是获取消息的事件随机。

The notification runs sometimes. JavaScript is getting message event randomly.

编辑2:

我肯定知道这个问题。

从Java文件,它通过点击推送通知消息打开应用程序时触发的JavaScript code。但在那个时候,web视图未加载,所以不能执行的脚本(它是一个事件触发)。这是一个使用插件将经历相同的条件下,每一个人。有没有解决办法或它的任何修正?

From the java file, it triggers the javascript code when opening the app by clicking on the push notification message. But at that time, the WebView is not loaded, so not able to execute the script (which is an event trigger). Is this is the condition, everyone using the plugin will experience the same. Is there any workaround or any fix for it?

难道我做错什么?

推荐答案

我已经找到了一个简单的解决方案。 在GCMIntentService,之前发送的JavaScript检查是否加载web视图:

i've found a simple solution. In the GCMIntentService, just before send javascript check if the webview is loaded :

while (GCMPlugin.gwebView == null || GCMPlugin.gwebView.webView == null || !GCMPlugin.gwebView.webView.isEnabled()) {
    // Wait until webView is enabled
}
GCMPlugin.sendJavascript(json);

这对我的作品......也许是一个很好的choise也为了添加超时prevent无限循环(这不应该发生,但...)

This works for me ... maybe is a good choise to add also a timeout in order to prevent an infinite loop ( it shouldn't happen but ... )

达维德

这篇关于当应用程序没有运行GCM科尔多瓦推送通知无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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