以下是我的 PHP 代码,它向 web 服务请求发送响应:
$query = "select name,email,password from User where email='".$email."' AND password='".$password."'";
$result = mysql_query($query);
$num_rows = mysql_num_rows($result);
if($num_rows==1)
{
sendResponse(200, json_encode("match"));
}
if($num_rows==0)
{
sendResponse(204, json_encode("not match"));
}
以下是我的 iOS 代码:
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
NSString *status = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@" Returned Json data : %@",status);
if ([status isEqualToString:@"match"])
{
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
[appDelegate OpenTabController];
}
//Boolean flag = [status isEqualToString:@"not match"];
//NSLog(@"flag : %d",flag);
if ([status isEqualToString:@"not match"])
{
NSLog(@"not match");
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:@"Invalid email or password"
message:@""
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
}
}
线[status isEqualToString:@"not match"]
不工作。