【问题标题】:phonegap, firebase, push notificationphonegap, firebase, 推送通知
【发布时间】:2018-12-17 03:08:57
【问题描述】:

我无法从 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
                );
           });
        }
    };

【问题讨论】:

  • 你能对答案提供反馈吗?

标签: firebase notifications push phonegap


【解决方案1】:

您使用的似乎是已弃用的 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
    }
});

请注意 '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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-31
    • 2017-03-05
    相关资源
    最近更新 更多