简体   繁体   English

如何将数据从iPhone发送到服务器并在站点中显示

[英]How to send data from iPhone to a Server and show it in the site

What I've learned and things that I'm not sure about if I need: 我学到的东西以及不确定是否需要的东西:

  • A server like one of heroku provided. 像heroku之一这样的服务器。
  • A database to handle what I will send. 一个数据库来处理我将发送的内容。
  • Something written for backend and mostly its written in php. 一些为后端编写的东西,大部分是用php写的。
  • To send data from iPhone to server with NSData and NSUrl with json . 使用iPhone的NSData和json的NSUrl从iPhone发送数据到服务器。
  • To receive what I sent from iPhone and handle it. 接收我从iPhone发送来的内容并进行处理。

But I don't even know where to write PHP files to deploy on sites or anything about database creation. 但是我什至不知道在哪里写PHP文件以部署在网站上或有关数据库创建的任何内容。

At first start developing the web service .To start with a local server Use any webserver like XAMP,LAMP,tomcat,ect. 首先开始开发Web服务。要从本地服务器开始使用任何XAMP,LAMP,tomcat等网络服务器。

  1. create a database using the phpMyadmin from your browser and also a user name to use by your application. 在浏览器中使用phpMyadmin创建数据库,并使用应用程序使用用户名。

  2. Use the URL like localhost/home/../api.php to get the api which interacts to our application.it depends on the server you use and you can get it XAMP , LAMP 使用localhost / home /../ api.php之类的URL获取与我们的应用程序交互的api。它取决于您使用的服务器,您可以获取它XAMPLAMP

  3. Use php to code the api and for making the output in json, you can use json_encode() . 使用php编码api并在json中进行输出,可以使用json_encode()

  4. in Your iOS app, use a method to post the request, such as NSMutableURLRequest with required parameters. 在您的iOS应用中,使用一种方法来发布请求,例如带有必需参数的NSMutableURLRequest

  5. To make a request in json format you can use 要以json格式发出请求,您可以使用

    NSString *jsonRequest = [jsonDict JSONRepresentation]; NSString * jsonRequest = [jsonDict JSONRepresentation];

    This should be placed in the body of the post request. 这应该放在发布请求的正文中。 You can also use normal post 您也可以使用普通帖子
    request with parameters. 带参数的要求。 I depends on how you process your request at the api. 我取决于您如何在api上处理您的请求。

  6. To get the response from api, implement NSURLConnectionDataDelegate , 要从api获取响应,请实现NSURLConnectionDataDelegate,
    NSURLConnectionDataDelegate methods. NSURLConnectionDataDelegate方法。

  7. To get the json object from response 从响应中获取json对象

    json=[NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&error]; json = [NSJSONSerialization JSONObjectWithData:responseData选项:NSJSONReadingMutableLeaves错误:&error];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM