I had developed an API Rest for an iPhone Game and it works properly. But I have a problem in iPhone that in each Response I had to check if session expired. I think that it is not so good, because I am copying the same piece of code on every response handler.
I think that I could make a helper or wrapper class for checking if session expire and if it happens, it will tries to get new session cookie.
I want to know if exist a native or better way to check expiration time session?
NSURLConnection should handle cookies for you. If your cookie has expired, on the next call you make you should get a 401 response.
Depending on how you implemented your calls you should have a method such as:
response.statuscode will be 401 if the cookie is expired. From here you can do the necessary re-validation that your app requires.