arnesson / cordova-plugin-firebase

Cordova plugin for Google Firebase
http://arnesson.github.io/cordova-plugin-firebase
MIT License
1.01k stars 1.56k forks source link

iOS app crashes after second launch on device #795

Open phonenatural opened 6 years ago

phonenatural commented 6 years ago

Hey guys, after a lot of investigation i have no clue of what could be the problem here. I have an iOS app developed with cordova and using this plugin for notifications.

When i run my app on my device with Xcode for the first time everything works fine, the notifications arrive and the app works great. The problem starts when i stop the app on Xcode and try to open it on my device without using Xcode, the app crashes on the splash screen. If i send any notification, it arrives with no issue, but when i open one notification the app just crashes on the splash screen again.

I have created all certificates and the development, production and ad-hoc provisioning profiles on my apple developer account, created and APNs Key to store on my Firebase Account, I have the file GoogleService-Info.plist on my Resources folders (platforms/ios/AppName/Resources & platforms/ios/AppName/Resources/Resources).

The only error that i can see on my log is this one

Unable to connect to FCM. Error Domain=com.google.fcm Code=2001 "FIRMessaging is already connected"

... this one

The object does not respond to -messaging:didReceiveRegistrationToken:, nor -messaging:didRefreshRegistrationToken:. Please implement -messaging:didReceiveRegistrationToken: to be provided with an FCM token.

And this one

[Firebase/Messaging][I-FCM002023] The object does not respond to -messaging:didReceiveRegistrationToken:, nor -messaging:didRefreshRegistrationToken:. Please implement -messaging:didReceiveRegistrationToken: to be provided with an FCM token.

This errors are shown when i accept the notification permission bubble.

Here is my JS for handling notifications:

function firebasePUSH() {
if (device.platform === "iOS") {
    window.FirebasePlugin.hasPermission(function (data) {
        if (!data.isEnabled) {
            window.FirebasePlugin.grantPermission();
        }
    });
}
window.FirebasePlugin.onNotificationOpen(function (notification) {
    console.log("tipo de notificacion " + notification.tipo);
    console.log(notification);
    if (notification.tipo === "alerta") {
        var parametros = {
            id: notification.numero,
            categoria: "rescato"
        };
        myApp.request.post("http://190.98.210.41/comuna/app/contactos.php", parametros, function (data) {
            var json = JSON.parse(data);
            console.log(json);
            if (json.error === false) {
                mostrarSOS(json.alerta);
            }
        });

    } else if (notification.tipo === "chat" || notification.tipo === "salud" || notification.tipo === "seguridad" || notification.tipo === "contacto" || notification.tipo === "oficina") {
        aceptarLlamada();
    } else if (notification.tipo === "publicidad") {
        mostrarPublicidad(notification.numero);
    } else if (notification.tipo === "sondeo") {
        mostrarSondeo(notification.numero);
    }
}, function (error) {
    console.error("onResume>>" + error);
});

window.FirebasePlugin.getToken(function (token) {
    try {
        var jsonToken = JSON.parse(token);
        token = jsonToken.token;
        console.warn("venia json: " + jsonToken.token);
    }
    catch (err) {
        console.warn("viene json limpio: " + token);
    }

    console.log("getToken js: " + token);
    localStorage.setItem('registrationId', token);
    /*PEGRUNTA SI YA ESTA LOGEADO*/
    if (localStorage.getItem("correo") !== null && localStorage.getItem("clave") !== null) {
        //pasa a la pantalla principal
        var parametros = {
            "id": localStorage.getItem("id"),
            "token": localStorage.getItem('registrationId'),
            "categoria": "token",
            format: "json",
            callback: function () {
                return true;
            }
        };
        myApp.request.json("http://190.98.210.41/comuna/app/usuario_get.php", parametros, function (data) {
            console.log(data);
        }, function (error) {
            console.log(error);
        });
    }

}, function (error) {
    console.error("getToken error: " + error);
});

window.FirebasePlugin.onTokenRefresh(function (token) {
    try {
        var jsonToken = JSON.parse(token);
        token = jsonToken.token;
        console.warn("token json: " + jsonToken.token);
    }
    catch (err) {
        console.warn("token limpio: " + token);
    }

    console.log("onTokenRefresh js: " + token);
    localStorage.setItem('registrationId', token);
    /*PEGRUNTA SI YA ESTA LOGEADO*/
    if (localStorage.getItem("correo") != null && localStorage.getItem("clave") != null) {
        //pasa a la pantalla principal
        var parametros = {
            "id": localStorage.getItem("id"),
            "token": localStorage.getItem('registrationId'),
            "categoria": "token",
            format: "json",
            callback: function () {
                return true;
            }
        };
        myApp.request.json("http://190.98.210.41/comuna/app/usuario_get.php", parametros, function (data) {
            console.log(data);
        }, function (error) {
            console.log(error);
        });

    }
}, function (error) {
    console.error(error);
});
}

I could use some help on this issue because i have been on this for weeks and i'm getting so frustrated. Thank you very much guys.

fdambrosio commented 6 years ago

I have the same problem, on iOS I get this error too: the default Firebase app has not yet been configured. Add [FIRApp configure] to your application initialization

m1nka commented 6 years ago

I have the same problem. I get The object does not respond to -messaging:didReceiveRegistrationToken:, nor -messaging:didRefreshRegistrationToken:. Please implement -messaging:didReceiveRegistrationToken: to be provided with an FCM toke after the second app launch.

soumak77 commented 6 years ago

@phonenatural @fdambrosio @m1nka are you still seeing this issue with v2 of the plugin?

windwp commented 6 years ago

Hi I upgrade plugin from v1 to v2 and this bug happen. I can't run app on ios emulator or real-device. it crash in splashscreen. maybe it is a problem with crashlytics

fdambrosio commented 6 years ago

yes @soumak77 I have the same problem using firebase 2 on iOS emulator/device

briantq commented 6 years ago

@windwp I am 99% sure you are hitting issue #848 Are you ever able to get it to launch correctly? If not, it's definitely #848.

@fdambrosio similar to above, are you able to launch it successfully? The issue mentions the second launch is failing. If it crashes on every launch it is most likely #848.

fdambrosio commented 6 years ago

thanks @briantq never able to launch it....