Ionic Webview在第一次启动IOS时没有同步cookies。

问题描述 投票:1回答:1

请帮助!!!!!!!!!!!! 我正在使用Ionic 5与Angular和Cordova。我的应用程序在浏览器和Android设备上测试时工作得很完美,但当它通过Xcode首次安装在我的设备(iphone)上时,cookie无法正确接收或发送。我的应用程序使用基于cookie的验证,所以当我得到登录响应时,它将有一个cookie,应该与所有后续请求一起发送。然而,在安装后的第一次启动时,我根本无法登录。当我退出并重新启动我的应用程序时,它可以完美地工作。我相信这是由于webview没有正确同步cookie造成的。我已经尝试了这个帖子中的所有解决方案。https:/github.comTelerik-Verified-PluginsWKWebViewissues247。 但插件太过时了,我无法让它正常工作。

我一直在寻找一个解决方案,几个星期,完全卡住了,并在这一点上用尽。我是新的Ionic和一般的开发,所以任何帮助将是非常感激! 我会提供任何有帮助的代码或截图,只是让我知道我应该分享什么。

angular ionic-framework webview cordova-plugins wkwebview
1个回答
0
投票

我不知道你是否已经解决了这个问题,因为你问了已经24天了,但是。

我有一个类似的问题。我使用的是cordova-plugin-wkwebview-cookie-sync插件,即使设置了cookie,但页面加载的时候却没有。我所要做的就是将$('body').append(_return);更新为$('body').html(_return);然后内容就使用cookie显示出来了。

这是我的代码。

function loadApp() {
  $.ajax({
    // this url sets the cookie when called
    url: "example.com",
    success: function (_return) {
      if (_return) {
        // the _return value uses the cookie to display custom data
        // I previously used the append() method here
        $("body").html(_return);
      }
    },
  });
}

document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady() {
  wkWebView.injectCookie(
    "www.example.com/index",
    function () {
      // success callback
      loadApp();
    },
    function () {
      // error callback
      //alert('error');
    }
  );
}
© www.soinside.com 2019 - 2024. All rights reserved.