2009-07-25 36 views
3

我想知道如何管理用戶在iPhone本機應用程序上的登錄和註銷。例如,每當我的應用程序運行時,用戶都必須登錄。該應用程序提供的信息以及它在運行php + mysql的網站上的用戶列表。 這是什麼「標準」程序?是否有任何庫用於處理用戶在遠程站點上的登錄?在iPhone應用程序上登錄/註銷

您使用了哪些解決方案?餅乾? PHP會話?

任何幫助或鏈接到有用的網站將不勝感激。

+0

你說的是一個原生iPhone應用程序,或針對iPhone的設備上運行的Web應用程序加載的用戶名和密碼類的方法? – 2009-07-25 20:45:28

+0

我正在談論一個本地iPhone應用程序。 – Hectoret 2009-07-25 21:02:54

回答

1

我個人獲取用戶輸入一次登錄信息,將其存儲在一個首選項文件,然後使用該保存的信息當過服務器請求的用戶進行身份驗證 - 如果你使用NSURLConnection的,那麼你可以使用這樣的:

-(void)connection:(NSURLConnection *)connection 
didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge{ 

if ([challenge previousFailureCount] == 0) { 
    NSURLCredential *newCredential; 
    newCredential=[NSURLCredential credentialWithUser:[UserManager getUsername] 
              password:[UserManager getPassword] 
              persistence:NSURLCredentialPersistenceNone]; 
    [[challenge sender] useCredential:newCredential 
      forAuthenticationChallenge:challenge]; 

} else { 

    [[challenge sender] cancelAuthenticationChallenge:challenge]; 
    // inform the user that the user name and password 
    // in the preferences are incorrect 
} 
} 

其中[UserManager getUsername][UserManager getPassword]是一類將一個首選項文件

+0

這個*應該*正在工作,但我認爲有一個錯誤'NSURLCredentialPersistenceNone'被忽略,並且認證細節被緩存。 (嘗試做兩個調用,首先正確,然後第二個不正確...函數將只在第一次被評估,並且兩個都會成功) – Marius 2011-05-18 18:23:46