javascript - PhoneGap 推送插件注册 ID 在移动设备上不起作用

标签 javascript android cordova push-notification phonegap-plugins

谁能帮助我,我将不胜感激 我需要检索每个设备和服务器 phonegap 的 regid 并为我服务,但是当我在 android 设备上模拟时,不再显示 id

index.js

var app = {
    initialize: function() {
        this.bindEvents();
    },
    bindEvents: function() {
        document.addEventListener('deviceready', this.onDeviceReady, false);
        document.getElementById("toggleBtn").addEventListener('click', this.toggle, false);
    },
    onDeviceReady: function() {
      console.log('deviceready event');
       app.push = PushNotification.init({
            "android": {
                "senderID": "143828535864"
            },
            "ios": {},
            "windows": {}
        });

       app.push.on('registration', function(data) {
           console.log("registration event: " + data.registrationId);
           document.getElementById("regId").innerHTML = data.registrationId;
           alert(data.registrationId);
           var oldRegId = localStorage.getItem('registrationId');
           var idReg=jQuery("#idReg").val(data.registrationId);


           if (oldRegId !== data.registrationId) {
               // Save new registration ID
               localStorage.setItem('registrationId', data.registrationId);
           }
       });
    },
};
 app.initialize();

和 config.xml

<content src="index.html" />
    <plugin name="cordova-plugin-whitelist" spec="1" />
    <access origin="*" />
    <allow-navigation href="*" />
    <allow-navigation href="http://*/*" />
    <allow-navigation href="https://*/*" />
    <allow-navigation href="data:*" />
    <allow-intent href="*" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="tel:*" />
    <allow-intent href="sms:*" />
    <allow-intent href="mailto:*" />
    <allow-intent href="geo:*" />
    <platform name="android">
        <allow-intent href="market:*" />
    </platform>
    <platform name="ios">
        <allow-intent href="itms:*" />
        <allow-intent href="itms-apps:*" />
    </platform>
    <!--<plugin name="PushPlugin" value="com.plugin.gcm.PushPlugin" />-->
    <plugin name="phonegap-plugin-push" spec="~1.7.2" />
    <plugin name="cordova-plugin-whitelist" spec="1" />
    <plugin name="cordova-plugin-device" spec="0.2.3" /> 

最佳答案

首先检查 Google 开发人员控制台项目中的发件人 ID 并尝试进行以下更改。

app.push = PushNotification.init({
            "android": {
                "senderID": "143828535864"
            }
        }); 

关于javascript - PhoneGap 推送插件注册 ID 在移动设备上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38427316/

相关文章:

iphone - 一步一步为 iOS 编写自己的手机间隙插件

Javascript: Uncaught ReferenceError

javascript - instanceof 自定义错误类返回 false

javascript - 单击删除按钮时从无序列表中删除特定列表项

java - 将 ArrayList 添加到另一个 ArrayList 中

android - Ionic Cordova Build Android找不到安装的构建工具

javascript - 仅当我在 chrome 调试器中附加断点时,验证时间输入才有效

android - 如何使用图表引擎在 TabHost 中显示销售图表

android - firebase 等于多个值

java - 重复的 dex 但没有重复的 .jar