Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/44.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何通过php通知我的iPhone应用程序某个名称是否已添加到数据库中?_Php_Iphone_Mysql_Objective C - Fatal编程技术网

如何通过php通知我的iPhone应用程序某个名称是否已添加到数据库中?

如何通过php通知我的iPhone应用程序某个名称是否已添加到数据库中?,php,iphone,mysql,objective-c,Php,Iphone,Mysql,Objective C,我的iPhone应用程序通过php文件与mySql数据库通信。一切正常。但是,当我发送表单并且用户名已经存在时,php文件应该以某种方式与通知相反。我该怎么办 function sendResponse($status = 200, $body = '', $content_type = 'text/html') { $status_header = 'HTTP/1.1 ' . $status . ' ' . 'OK'; header($status_header); h

我的iPhone应用程序通过php文件与mySql数据库通信。一切正常。但是,当我发送表单并且用户名已经存在时,php文件应该以某种方式与通知相反。我该怎么办

function sendResponse($status = 200, $body = '', $content_type = 'text/html')
{
    $status_header = 'HTTP/1.1 ' . $status . ' ' . 'OK';
    header($status_header);
    header('Content-type: ' . $content_type);
    echo $body;
}
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 ? 
    }
function sendResponse($status = 200, $body = '', $content_type = 'text/html')
{
    $status_header = 'HTTP/1.1 ' . $status . ' ' . 'OK';
    header($status_header);
    header('Content-type: ' . $content_type);
    echo $body;
}
我可以想出一个办法,但我认为有一个更好更有效的办法

function sendResponse($status = 200, $body = '', $content_type = 'text/html')
{
    $status_header = 'HTTP/1.1 ' . $status . ' ' . 'OK';
    header($status_header);
    header('Content-type: ' . $content_type);
    echo $body;
}
[编辑]

function sendResponse($status = 200, $body = '', $content_type = 'text/html')
{
    $status_header = 'HTTP/1.1 ' . $status . ' ' . 'OK';
    header($status_header);
    header('Content-type: ' . $content_type);
    echo $body;
}
这就是我所做的,以得到回应:

 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);
function sendResponse($status = 200, $body = '', $content_type = 'text/html')
{
    $status_header = 'HTTP/1.1 ' . $status . ' ' . 'OK';
    header($status_header);
    header('Content-type: ' . $content_type);
    echo $body;
}

[/EDIT]他实际上不需要推送通知。只需要从服务器返回一个响应

$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 ? 
sendResponse(200, json_encode('SUCCESS Notification'));
}
function sendResponse($status = 200, $body = '', $content_type = 'text/html')
{
    $status_header = 'HTTP/1.1 ' . $status . ' ' . 'OK';
    header($status_header);
    header('Content-type: ' . $content_type);
    echo $body;
}
sendResponse看起来像这样

function sendResponse($status = 200, $body = '', $content_type = 'text/html')
{
    $status_header = 'HTTP/1.1 ' . $status . ' ' . 'OK';
    header($status_header);
    header('Content-type: ' . $content_type);
    echo $body;
}
//用于发送HTTP响应代码/消息的帮助器方法

function sendResponse($status = 200, $body = '', $content_type = 'text/html')
{
    $status_header = 'HTTP/1.1 ' . $status . ' ' . 'OK';
    header($status_header);
    header('Content-type: ' . $content_type);
    echo $body;
}

对不起,我不太理解这种情况。iOS应用程序将数据发送到服务器,服务器试图将数据放入数据库,您想知道服务器应如何响应无效请求吗?不,我的应用程序将数据发送到php文件。此php文件尝试添加用户名,如果不成功,则应将某些内容返回到应用程序。或者至少应用程序应该知道数据库中已经存在用户名。。。我该怎么做?嗯,正是我说的。应用程序向您的服务器发送HTTP请求(?),您的服务器执行某些操作并返回响应。您希望返回一个表示操作无法完成的响应。您目前是如何发送请求的?好的,这正是我想要的,谢谢。你知道我的应用程序应该是什么样子吗?不明白你的问题。。。“应用程序看起来应该是这样的…”意思是?哦,对不起,把事情搞砸了。我的意思是“应用程序应该做什么”和“我的应用程序应该注意”。我不知道如何处理我的应用程序中的响应。我在我的问题中贴了一些代码,试图得到答案,但不幸的是没有成功。如果您仔细查看,我将不胜感激。我想如果是成功通知,您将继续您的正常流程。否则会在应用程序中显示错误..或应用程序中的任何流