【发布时间】:2014-04-16 13:19:20
【问题描述】:
对于 phonegap 构建的push notifications plugin,我无法接收任何类型的回调,我已将插件包含在 config.xml 中。
我已注册GCM 并获得了 pushNotification.register() 所需的项目编号。
我还可以访问 window.plugins.pushNotification 对象,所以我知道它包含在插件中。
- PhoneGap 构建版本: 3.1
- 补水:已禁用
- 调试:已启用
- 设备: 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()
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对象的函数。
如果我不输入发件人 ID,我会收到一条错误消息,指出没有发件人 ID,因此我知道某些东西正在工作。有什么想法太令人沮丧了?
PS - 我还注意到一些奇怪的事情,当我 console.log 时 window.plugins.pushNotification 它返回一个空对象,但是我仍然可以调用 window.plugins.pushNotification.register(),但我想我将在 console.log 中可见。
【问题讨论】:
标签: android cordova push-notification phonegap-plugins