PhoneGap的构建推送通知(安卓) [英] PhoneGap Build Push Notification (Android)
问题描述
我无法接收到任何类型的回调,为推送通知插件获得的PhoneGap构建,我已经包含插件里面的config.xml。
I am having trouble receiving any type of callback for the push notifications plugin for phonegap build, I have included the plugin inside config.xml.
我已经签署了 GCM 并得到了我所需要的pushNotification.register项目数()。
I have signed up to GCM and got my project number needed for pushNotification.register().
我也有机会获得window.plugins.pushNotification对象,所以我知道它包含了插件。
I also have access to the window.plugins.pushNotification object so I know it's included the plugin.
- 的PhoneGap Build版本: 3.1
- 保湿:禁用
- 调试:启用
- 设备:三星标签2
- PhoneGap Build Version: 3.1
- Hydration: Disabled
- Debug: Enabled
- Device: Samsung Tab 2
我的 index.html的包含js文件是:
<script type="text/javascript" src="phonegap.js"></script>
<script type="text/javascript" src="PushNotification.js"></script>
<script type="text/javascript" src="js/lib/jquery.js" ></script>
<script type="text/javascript" src="js/lib/handlebars.js"></script>
<script type="text/javascript" src="js/handlebars/helpers.js"></script>
<script type="text/javascript" src="js/plugins/fastclick.js"></script>
<script type="text/javascript" src="js/app.js"></script>
我的 config.xml中包括插件是:
// plugins
<gap:plugin name="org.apache.cordova.console" />
<gap:plugin name="org.apache.cordova.device" />
<gap:plugin name="org.apache.cordova.geolocation" />
<gap:plugin name="org.apache.cordova.dialogs" />
<gap:plugin name="org.apache.cordova.inappbrowser" />
<gap:plugin name="org.apache.cordova.splashscreen" />
<gap:plugin name="com.phonegap.plugins.pushplugin" />
// access to external domains
<access origin="*"/>
我的app.js来电pushNotification.register()
My app.js call to pushNotification.register()
var app = {
init: function() {
document.addEventListener("deviceready", this.onDeviceReady, false);
},
onDeviceReady: function(){
// DO STUFF
// ....
// ENABLE PUSH
this.push_init();
},
push_init: function(){
app.SENDER_ID = 123456789; // replaced by my actual GCM project no
var pushNotification = window.plugins.pushNotification;
pushNotification.register(
function(){alert('Push: win');}, // never called
function(){alert('Push: Error');}, // never called
{ senderID: app.SENDER_ID, ecb: "app.push_android" }
);
},
// never called
push_android: function(e){
alert('connection established...');
console.log( 'successfully started android' );
console.log( e );
}
};
// start the app
app.init();
在被称为没有被执行时,app.push_android()是应用程序对象的函数。
After that is called nothing is executed, app.push_android() is a function of app object.
如果我没有进入senderID我得到一个错误说没有发件人ID,所以我知道的东西是工作。这是如此令人沮丧的任何想法?
If i don't enter a senderID I get an error saying no sender ID so I know that something is working. This is so frustrating any ideas?
PS - 我也发现了一些奇怪的,当我CONSOLE.LOG它返回一个空的对象window.plugins.pushNotification,但是我仍然可以调用window.plugins.pushNotification.register(),但我想我将是的console.log内部可见。
推荐答案
我想我已经找到了解决办法。
I think I've found the solution.
我是在对象传递一个字符串属性senderID的整数,而不是
I was passing an integer instead of a string for the property senderID in the object
不工作
pushNotification.register(
function(){alert('Push: win');}, // NOT called
function(){alert('Push: Error');}, // NOT called
{ senderID: 123456789, ecb: "app.push_android" }
);
不工作
pushNotification.register(
function(){alert('Push: win');}, // called
function(){alert('Push: Error');}, // called
{ senderID: "123456789", ecb: "app.push_android" }
);
这篇关于PhoneGap的构建推送通知(安卓)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!