简体   繁体   中英

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

I've created a cordova project with Visual Studio Code. I'm using this plugin: phonegap-plugin-push and I've follow the instructions.

I need to use notifications. I'm using Firebase and I've downloaded google-services.json, put it in my root, ran on Android and tested from Firebase cloud messaging. Everything works.

The problem: iOS. I've downloaded GoogleService-Info.plist, put on my root project and root platform ios. Downloaded the p8 certificates from apple developer console and put on Firebase console:

在此处输入图片说明

So, when I launch this on 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);
    });
}

I receive the token on my iOS device (iPad & iPhone), but when I try to test it from Firebase, I can't see my devices registered token. Why? What I'm doing wrong?

I assume you are using the latest version of cordova-plugin-push (v2.2.3)?

Did you include the following in Cordova's config.xml?

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

Failing this please check the value of data.registrationType in your .on('registration') callback. The value should be FCM . If it's returning APNS then the registrationId will be a raw APNs token, not a Firebase token, in which case something in your configuration is amiss.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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