PhoneGap 构建推送通知 (Android) [英] PhoneGap Build Push Notification (Android)

查看:16
本文介绍了PhoneGap 构建推送通知 (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 所需的项目编号.注册().

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
  • 补水:已禁用
  • 调试:已启用
  • 设备:三星 Tab 2
  • PhoneGap Build Version: 3.1
  • Hydration: Disabled
  • Debug: Enabled
  • Device: Samsung Tab 2

我的 index.html js 文件包括:

My index.html js files included are:

<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()是app对象的一个​​函数.

After that is called nothing is executed, app.push_android() is a function of app object.

如果我没有输入发件人 ID,我会收到一条错误消息,说没有发件人 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 构建推送通知 (Android)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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