IPhone - UIWebview does not save authentication on sites

For these purposes, let's say I have an application that contains one UIWebview view.

I upload a request to any of these sites: facebook, gmail, twitter, etc. and get the login screen.

The fact is that if I log in and restart the application, I will have to go through the login screen again.

In the Mobile Safari / Google application, for example, I would save my data in a cookie / session / whatnot and would not need to re-enter the user credentials. This is the behavior I want to have.

The material I tried:

  • sending cookies from NSHTTPCookieStorage via NSURLRequest.
  • Saving cookies directly to NSUserDefaults, but not luck.

How can I achieve Mobile Safari and Google app behavior?

+5
source share
2 answers

Cookies must be archived and saved when the application is completed, and then reloaded when the application becomes active. You can achieve this by:

[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookies:cookies forURL:url mainDocumentURL:nil]; // where cookies is the unarchived array of cookies

+5
source

Use the asiHTTPrequest class. It helped me a lot in my projects.

-1
source

All Articles