如何在iPhone上创建和维护身份验证会话?

如何在iPhone上创建和维护身份验证会话?

问题描述:

我要创建一个具有帐户系统的iphone应用程序. (登录/注销).

i am about to create an iphone application that will have a account system . ( login/logout ) .

也将具有服务器端.那么如何进行会话管理.当您的客户使用iphone时

that will have a server side also. so how to do session management. while your client is iphone

我该怎么做??

我使用 ASIHTTPRequest 库与我的Web服务进行通信.

I use the ASIHTTPRequest library to communicate with my webservice.

它具有处理cookie的内置功能,因此我只需使用POST请求登录,就可以像设置普通浏览器一样设置cookie.

It has built-in capability to handle cookies, so I simply login with a POST request and the cookie is set like a normal browser.

当网络连接断开时,您仍然可以检查有效的cookie:

When your network connection is down, you can still check for a valid cookie:

- (BOOL) hasSignInCookie
{
    NSArray *cookieJar = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies];
    for( NSHTTPCookie *cookie in cookieJar)
    {
        if( [[cookie name] compare: @"JourneyTagID"] == NSOrderedSame)
        {
            return YES;
        }
    }
    return NO;
}