views:

33

answers:

1

I'm building a Reddit client, for the iPad and the iPhone. I know there's some other clients, but I have some really cool ideas for tabbed Reddit browsing :D

Anywho, I'm working on the back-end of the thing first, and was wondering what the best way to deal with my cookie would be. I'm using ASIFormDataRequest and ASIHTTPRequest to get the cookie and make the requests for stories, and user subreddits. My question is, how do I know when the cookie has expired and I'm not logged in anymore?

A stupid solution (In my opinion) would be to just log in again before making any sort of data request... but that seems, well, stupid.

Another solution would be to check specifically for different responses for different requests to Reddit and derive my logged-in status.

An even BETTER way, would be to somehow see if I have a cookie in the iPhone's cookie store that is associated with Reddit, and if I don't, log in. So, is there a way to do that?

A: 

I don't have any specific knowledge about reddit, however the usual way to handle this would be to make the request, then see if you got an error saying "Not logged in" as the response.

Checking to see if there is a cookie in the store or not is possible, with

[[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:[url absoluteURL]]

however this will not tell you if the cookie is valid - it could have been expired on the server side or could have become invalid on the server side - so you will still have to check the responses for "Not logged in" errors. (Although it appears from the API documentation that reddit only sets session cookies, so they'll never appear in the persistent store - in that case you can use [ASIHTTPRequest sessionCookies] to see the cookies.)

JosephH