0

Assuming I have a e-commerce mobile site, where user can login, save some items in shopping cart, and checkout.

Can I point to this mobile site from my cordova app, and then expect the login/re-login will work? I.e. the user session and cookies will be kept correctly in Cordova Webviews?

p/s: I found an old question discussing this issue (Handling cookies in PhoneGap/Cordova), that was 4 years ago and I hope things are different now.

Community
  • 1
  • 1
mkto
  • 4,584
  • 5
  • 41
  • 65

1 Answers1

0

you can use "localStorage" to save session data

save:

 $window.localStorage['userinfo'] = JSON.stringify({
              username: user.username,
              password: user.password
            });

load:

  if ($window.localStorage['userinfo']) {
      var userinfo = $window.JSON.parse($window.localStorage['userinfo']);
      $scope.user.username = userinfo.username;
      $scope.user.password = userinfo.password;
    }
zoly01
  • 117
  • 2
  • Hmm ....The tricky part is that I have no control over the e-commerce site. It is maintained by another team. I was hoping the login/session will work as it is... – mkto Apr 25 '17 at 03:02
  • In android, webview cookie will be saved at "data/data/package_name/app_WebView/Cookies.db". If you can save the cookies here, and after that, you load the webview, the cookie will be send properly. I don't try this by myself, hope this will help you. you need write "native-code" to do this. Some code snippets:`CookieManager cookieManager = CookieManager.getInstance();` `cookieManager.setCookie(url, cookie);` – zoly01 Apr 25 '17 at 03:35