【问题标题】:Cordova iOS notifications with phonegap-plugin-push and Firebase. No work带有 phonegap-plugin-push 和 Firebase 的 Cordova iOS 通知。没有工作
【发布时间】:2019-04-11 00:44:05
【问题描述】:

我使用 Visual Studio Code 创建了一个 cordova 项目。我正在使用这个插件: phonegap-plugin-push 我已按照说明进行操作。

我需要使用通知。我正在使用 Firebase,我已经下载了 google-services.json,将它放在我的根目录中,在 Android 上运行并通过 Firebase 云消息传递进行了测试。一切正常。

问题:iOS。我已经下载了 GoogleService-Info.plist,放在我的根项目和根平台 ios 上。 从苹果开发者控制台下载 p8 证书并放到 Firebase 控制台:

所以,当我在 index.js 上启动它时,ondeviceready:

onDeviceReady: function() {
    this.receivedEvent('deviceready');
    //alert("ciao");

    app.push = PushNotification.init({
        "android": {
            "senderID": "xxxx"
        },
        "ios": {
          "senderID": "xxxx",
          "sound": true,
          "vibration": true,
          "badge": true
        },
        "windows": {}
    });

    app.push.on('registration', function(data) {
        alert(data.registrationId);
        console.log("registration event: " + data.registrationId);
        document.getElementById("regId").innerHTML = data.registrationId;
        var oldRegId = localStorage.getItem('registrationId');
        if (oldRegId !== data.registrationId) {
            // Save new registration ID
            localStorage.setItem('registrationId', data.registrationId);
            // Post registrationId to your app server as the value has changed
        }
    });

    app.push.on('notification', function(data) {
        console.log('notification event');
        alert("qualcosa ricevuto: " + data.message + data.title);
    });

    app.push.on('error', function(e) {
        //console.log("push error = " + e.message);
        alert("push error = " + e.message);
    });
}

我在我的 iOS 设备(iPad 和 iPhone)上收到了令牌,但是当我尝试从 Firebase 测试它时,我看不到我的设备注册的令牌。 为什么?我做错了什么?

【问题讨论】:

  • 您解决了这个问题吗? Pushnotification 对我来说是未定义的。请发布您的解决方案。
  • 没有还是不行,我用原生编程改了

标签: ios firebase cordova firebase-cloud-messaging phonegap-plugins


【解决方案1】:

我假设您使用的是最新版本的 cordova-plugin-push (v2.2.3)?

您是否在 Cordova 的 config.xml 中包含以下内容?

<platform name="ios">
    <resource-file src="GoogleService-Info.plist" />
</platform>

如果失败,请检查您的 .on('registration') 回调中的 data.registrationType 的值。该值应为FCM。如果它返回 APNS,则 registrationId 将是原始 APNs 令牌,而不是 Firebase 令牌,在这种情况下,您的配置中有问题。

【讨论】:

    猜你喜欢
    • 2017-06-18
    • 1970-01-01
    • 1970-01-01
    • 2018-07-06
    • 1970-01-01
    • 2019-01-11
    • 2020-04-22
    • 1970-01-01
    • 2016-10-20
    相关资源
    最近更新 更多