我想知道管理用户登录和注销IPhone原生应用程序。例如,每次我的应用程序运行时,用户都必须登录。应用程序提供的信息以及运行php + mysql的网站上的用户列表。 什么是“标准”程序?是否有用于在远程站点上处理用户登录的库?
您使用了哪些解决方案?饼干? php会话?
非常感谢任何有用网站的帮助或链接。
答案 0 :(得分: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]
是类中的类方法,用于从首选项文件加载用户名和密码