phonegap, firebase, 推送通知

phonegap, firebase, push notification

我无法收到来自 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
                );
           });
        }
    };

您似乎在使用已弃用的 Phonegap 推送插件版本。 请参阅此位置以获取较新版本: https://github.com/phonegap/phonegap-plugin-push

这意味着初始化函数应该如下所示:

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

请注意 'badge' 参数未在 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