我遇到了问题,无法接收任何形式的回调来使用PhoneGap Build的推送通知插件,我在config.xml文件中包含了该插件。
我已经注册了GCM并获取到了用于pushNotification.register()的项目编号。
我也可以访问window.plugins.pushNotification对象,所以我知道它已经包含了该插件。
- PhoneGap Build版本:3.1
- 水合:禁用
- 调试:启用
- 设备:三星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()。
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()是app对象的一个函数。
如果我不输入senderID,就会收到一个错误,指出没有发送者ID,所以我知道某些东西正在起作用。这真让人沮丧,你有什么想法吗?
PS - 我还注意到一些奇怪的事情,当我console.log window.plugins.pushNotification时,它返回一个空对象,但我仍然可以调用window.plugins.pushNotification.register(),但我想它应该在console.log中可见。