Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
730 views
in Technique[技术] by (71.8m points)

ionic framework - Can you use cookies in a Cordova application?

I have been building an android app using Ionic. At this point, I am under the impression that Cordova applications do not save or send the cookies that are served from a REST API server. If I run the application with the 'ionic serve' command I can see that my session and CSRF cookies are sent with my AJAX requests. However, when I run the code with the 'ionic emulate' command it does not appear that either are sent to my server.

I have seen some articles and threads that talk about using the setAcceptThirdPartyCookies() method in the class that extends CordovaActivity, but that hasn't worked for me.

I have tried using $httpProvider.defaults.withCredentials = true in my angular module config to no avail.

I have tried using ngCookies, but that doesn't appear to get a handle on the cookies from my API server either.

I just want to know once and for all if using cookies in a Cordova application is possible or not. If it isn't I will go with a token based approach. It would be nice to be able to use the same security configuration for the mobile app and web app though.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can't use cookies, you should use localStorage

Browsers provide a convenient module for storing data in a simple key <-> value fashion called localStorage. This is an object on window that we can get and set String values easily

See this for details


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...