如何从php Web服务向指定的ios设备发送消息

时间:2012-12-03 08:05:01

标签: ios response

我有一个用PHP编写的ios设备和一个Web服务。当ios设备向Web服务发送请求时,Web服务将响应该确切的ios设备。我不知道服务器如何向该设备发送响应。 谢谢你的帮助!

2 个答案:

答案 0 :(得分:0)

如果是移动网站或应用,您可以使用jquery ajax查询您的网络服务,如果有的话,将会产生响应。

答案 1 :(得分:0)

您可以研究每个组成部分:

1)App使用回调委托方法(ASIHttpRequest或AFNetworking)向Web服务发出HTTP POST请求

2)服务器接收请求,解析它,然后构造一个JSON响应并自动将其返回给应用程序(使用Web框架)

3)在app的委托回调方法中,您将JSON数据解析为NSDictionary。使用[yourDictionary valueForKey:@“name”];,[yourDictionary valueForKey:@“age”],[yourDictionary valueForKey:@“gender”],[yourDictionary valueForKey:@“email”]等提取JSON键值。

然后,您的应用可以在屏幕上显示已解析的数据,也可以使用它来执行其他操作。

修改

由于您使用PHP作为Web服务语言,我建议使用Symfony 2 Web框架。

你会写类似

的东西
// get request
$inputName = $_REQUEST['name'];

// ORM
$em = $this->getDoctrine()->getManager();

// find email based on name
$member = $em->getRepository('MyWebAppWebServiceBundle:Member')->findOneByName($inputName);

...

// construct JSON array
$json = array(
    'id' => $member->getId(),
    'name' => $member->getName(),
    'email' => $member->getEmail()
);

// send the response back to the user as JSON data
$response = new Response(json_encode($json));
$response->headers->set('Content-Type', 'application/json');
return $response;

或者,如果您需要可伸缩的应用程序,则可以使用Node.js(服务器端Javascript)