我的iPhone应用程序通过一个php文件与我的mySql数据库进行通信。一切正常。但是当我发送表单并且用户名已经存在时,php文件应该以某种方式回应通知。我该怎么办 ?
PHP文件
$query = "SELECT username FROM userData WHERE username = '$username'";
$result = mysql_query($query);
if (mysql_num_rows($result) > 0) {
// WHAT SHOULD BE DONE HERE TO NOTIFY iPHONE ?
}我可以想出一个办法,但我认为有一个更好,更有效的方法来做到这一点。
[编辑]
这就是我做得到的回应:
NSURLResponse *theResponse =[[NSURLResponse alloc]init];
NSError *error;
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&theResponse error:&error];
NSDictionary *jsonDictionaryResponse =[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
NSLog(@"json response = %@", jsonDictionaryResponse);[/编辑]