Search code examples
iphoneiosauthenticationcookiespersistence

Storing cookies to persist credentials for an iPhone app


I've been doing a bit of research on the subject, and I'm a little confused about storing cookies within an iOS app. I want to be able to store a user's login credentials so that they don't have to log in every time they launch the app (much like Facebook's app does). I'm kind of lost on how to do that though. Here are some of the specific questions I have:

  1. When the user logs in, does a cookie get stored automatically? If so, where? If not, how do I store it?

  2. How can I check for that cookie and access it, examine it, etc.? Maybe on a relaunch of the app or something.

  3. How is storing a cookie with user credentials different than storing them in the keychain? Or are they the same thing?

  4. When a user presses "logout" in the app, should that delete the persistent cookie? It must, right?

  5. What's the best way to store these cookies? What does iOS automatically do for you, and what do you have to do yourself?

  6. Is there an advantage to using ASIHTTP stuff for things like this? If so, what does the ASI library offer that the NSURL stuff doesn't? Does the treatment of cookies change when using the ASIHTTP library?

As I'm sure you can tell, I'm pretty lost, and don't know all that much about how cookies work, but I'm trying to figure it out, and any help is much appreciated!


Solution

  • Are you using a webview for your app or something?

    Update:

    You should store the username/password combination in the keychain. There are several wrappers available for this, one of my favorites: Keychain Swift

    It is however; more secure to use an access token so that the username and password combination are never stored on device.