Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone - UIWebview doesn't save authentication to sites

For these purposes, let say I have an application which contains a single UIWebview.

I'm loading a request to any of these sites: facebook, gmail, twitter, etc., and receive a login screen.

The thing is - that if I log in and relaunch the app, I will have to go through the login screen again.

In Mobile Safari/Google app for example I would retain my login cookie/session details/whatnot and wouldn't need to enter my user credentials again. That is the behavior I want to have.

Stuff I tried:

  • sending cookies from the NSHTTPCookieStorage via the NSURLRequest.
  • Persisting the cookies myself to NSUserDefaults, but no luck.

How can I achieve the behavior Mobile Safari & Google app has?

like image 776
Gilbert Avatar asked Dec 20 '10 16:12

Gilbert


1 Answers

The cookies should be archived and persisted when the app is terminated and later reloaded when the app becomes active. You can achieve this by:

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

like image 82
Matthew Purland Avatar answered Sep 21 '22 20:09

Matthew Purland