菜鸟教程小白 发表于 2022-12-11 20:26:14

ios - Cordova iOS 应用程序在设备上第二次启动后崩溃


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

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

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

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

<blockquote>
<p>Unable to connect to FCM. Error Domain=com.google.fcm Code=2001 &#34;FIRMessaging is already connected&#34; </p>
</blockquote>

<p>还有这个</p>

<blockquote>
<p>The objectdoes not respond to -messaging:didReceiveRegistrationToken:, nor -messaging:didRefreshRegistrationToken:. Please implement -messaging:didReceiveRegistrationToken: to be provided with an FCM token.</p>
</blockquote>

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

<p>这是我处理通知的 JS:</p>

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

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

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

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

}, function (error) {
    console.error(&#34;getToken error: &#34; + error);
});

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

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

    }
}, function (error) {
    console.error(error);
});
</code></pre>

<p>}</p>

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

<p><strong>编辑:</strong></p>

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

<blockquote>
<p> The objectdoes not respond to -messaging:didReceiveRegistrationToken:, nor -messaging:didRefreshRegistrationToken:. Please implement -messaging:didReceiveRegistrationToken: to be provided with an FCM token.</p>
</blockquote></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>我遇到了一个非常相似的问题.. </p>

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

<p>在没有多次请求许可的情况下进行一项测试..</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - Cordova iOS 应用程序在设备上第二次启动后崩溃,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/51714141/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/51714141/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - Cordova iOS 应用程序在设备上第二次启动后崩溃