OGeek|极客世界-中国程序员成长平台

标题: ios - Cordova iOS 应用程序在设备上第二次启动后崩溃 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 20:26
标题: ios - Cordova iOS 应用程序在设备上第二次启动后崩溃

经过大量调查,我不知道这里可能存在什么问题。我有一个使用 cordova 开发的 iOS 应用程序,并使用 Firebase (cordova-plugin-firebase) 进行通知。

当我第一次使用 Xcode 在我的设备上运行我的应用程序时,一切正常,通知到达并且应用程序运行良好。当我在 Xcode 上停止应用程序并尝试在我的设备上打开它而不使用 Xcode 时,问题就开始了,应用程序在启动屏幕上崩溃。如果我发送任何通知,它会毫无问题地到达,但是当我打开一个通知时,应用程序会再次在启动屏幕上崩溃。

我已经在我的苹果开发者帐户上创建了所有证书以及开发、生产和临时配置文件,创建了 APNs key 来存储在我的 Firebase 帐户中,我的资源文件夹中有 GoogleService-Info.plist 文件(平台/ios/AppName/资源和平台/ios/AppName/Resources/Resources)。

我能在日志中看到的唯一错误就是这个

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

还有这个

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

当我接受通知权限气泡时会显示此错误。

这是我处理通知的 JS:

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);
});

}

我可以在这个问题上使用一些帮助,因为我已经为此工作了好几个星期,我感到非常沮丧。非常感谢你们。

编辑:

我在启动应用程序时发现了第三个错误。

[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.



Best Answer-推荐答案


我遇到了一个非常相似的问题..

我发现问题出在我第二次调用 window.FirebasePlugin.grantPermission() 时。

在没有多次请求许可的情况下进行一项测试..

关于ios - Cordova iOS 应用程序在设备上第二次启动后崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51714141/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4