phonegap,firebase,推送通知

时间:2018-07-09 12:17:11

标签: firebase notifications push phonegap

我无法从Firebase收到通知以显示。我遵循了here提供的教程。可能是什么问题呢?

сode example : 
        setupPush: function() {
            var push = PushNotification.init({
                "android": {
                    "senderID": "966613396976",
                    "sound": true,
                    "vibration": true,
                    "badge": true
                },
                "browser": {},
                "ios": {
                    "sound": true,
                    "vibration": true,
                    "badge": true
                },
                "windows": {}
            });
            push.on('registration', function(data) {
                test(data);
                var oldRegId = localStorage.getItem('registrationId');
                if (oldRegId !== data.registrationId) {
                    localStorage.setItem('registrationId', data.registrationId); 
                }  
            });
            push.on('error', function(e) {
                console.log("push error = " + e.message);
            });
            push.on('notification', function(data) {
                console.log('notification event');
                navigator.notification.alert(
                    data.message,         // message
                    null,                 // callback
                    data.title,           // title
                    'Ok'                  // buttonName
                );
           });
        }
    };

1 个答案:

答案 0 :(得分:0)

您似乎正在使用不推荐使用的Phonegap推送插件版本。 请查看以下位置以获取较新的版本: https://github.com/phonegap/phonegap-plugin-push

这意味着init函数应如下所示:

const push = PushNotification.init({
    android: {
        vibrate: true,
        sound: true
    },
    ios: {
        fcmSandbox: false,
        alert: true,
        vibrate:true,
        badge: true,
        sound: true
    }
});

请注意,在Android中未使用“徽章”参数。 而且,您必须设置正确的config.xml文件:

它应该在其中:

<platform name="android">
  <resource-file src="google-services.json" target="/google-services.json" />
</platform>
<platform name="ios">
  <resource-file src="push/GoogleService-Info.plist" />
</platform>

<plugin name="phonegap-plugin-push" spec="2.0.0" source="npm" />

这仅适用于正确的版本: https://github.com/phonegap/phonegap-plugin-push/blob/master/docs/INSTALLATION.md

相关问题