繁体   English   中英

带有phonegap-plugin-push和Firebase的Cordova iOS通知。 没工作

[英]Cordova iOS notifications with phonegap-plugin-push and Firebase. No work

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

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

问题:iOS。 我已经下载了GoogleService-Info.plist,放在我的根项目和根平台ios中。 从Apple开发人员控制台下载了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测试令牌时,看不到我的设备已注册令牌。 为什么? 我做错了什么?

我假设您使用的是最新版本的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令牌,在这种情况下,配置中的内容不正确。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM