简体   繁体   English

iPhone网络

[英]iPhone Networking

If I have make an application, how would I make it interact with a database on a server of mine? 如果我有一个应用程序,我将如何使其与我的服务器上的数据库交互? I'm kind of lost, and don't know where to start. 我有点迷茫,不知道从哪里开始。

Vague question yields a vague answer. 模糊的问题产生模糊的答案。

It entirely depends on what kind of interaction you need. 这完全取决于您需要哪种类型的交互。 Lots of constant queries? 很多不断的查询? Few and far between? 几步之遥? Client side cache? 客户端缓存? Real time updates? 实时更新? All of these questions will impact the answer. 所有这些问题都会影响答案。

The easiest way is to go with an AJAX style HTTP based client/server type of interaction. 最简单的方法是使用基于AJAX样式的HTTP客户端/服务器类型的交互。 Sticking a database behind a web server has been done about a bazillion times and, thus, you'll find lots and lots of examples and, even, solutions with a few google searches. 将数据库粘贴到Web服务器之后已经进行了大约上万亿次,因此,您会发现很多示例,甚至还有一些Google搜索的解决方案。

You don't really need to use JavaScript (the J in AJAX). 您实际上不需要使用JavaScript(AJAX中的J)。 Instead, send over an HTTP request that encapsulates your query and have the server respond with an XML document containing the answer. 而是发送一个封装了查询的HTTP请求,并让服务器使用包含答案的XML文档进行响应。

If that won't work for you -- too much overhead, need to relay binary information (for which XML sucks), etc.. -- then you'll wan to go with more direct access to the database. 如果那对您不起作用-过多的开销,需要中继二进制信息(XML吸收这些信息)等等。-那么您将想直接访问数据库。 That is harder and can range from porting a client library to the iPhone to creating your own wire protocol. 这比较困难,范围从将客户端库移植到iPhone到创建自己的有线协议。

A significantly harder problem and you'll have to deal with networking issues -- firewalls, NAT, proxies, etc... -- that are generally already solved with HTTP. 这是一个非常困难的问题,您将不得不处理通常已通过HTTP解决的网络问题-防火墙,NAT,代理等...。

Stick with HTTP until you prove that it won't work. 坚持使用HTTP,直到证明它不起作用为止。 Much simpler. 简单得多。

Search for "http request" in the iPhone docs. 在iPhone文档中搜索“ http请求”。 HTTP client APIs are included. 包括HTTP客户端API。

You might try Apple's "Getting Started with Networking & Internet" or "Introduction to the URL Loading System" , in addition to the Networking section of the iPhone Application Programming Guide. 除了《 iPhone应用程序编程指南》的“ 网络”部分外,您还可以尝试使用Apple的“网络和Internet入门”“ URL加载系统简介 ”。 There are also several sample applications that handle networking of various types within the ADC's iPhone section. ADC的iPhone部分中还有一些示例应用程序可以处理各种类型的联网。

Additionally, there are a number of open source iPhone applications out there that handle networking, including my own . 此外,还有许多可处理网络的开源iPhone应用程序 ,包括我自己的

I had a similar question regarding a rails app - the answers there may help you. 对于Rails应用程序,我也有类似的问题-那里的答案可能会对您有所帮助。

What is the best approach for building an iphone client for a rails app? 为Rails应用构建iPhone客户端的最佳方法是什么?

But the answer really depends on your knowledge of iphone programming and server side programming, plus how your database is set up at the moment - but most likely you're going to need to write some kind of webservice / REST API that allows a remote client to do things with your database. 但是答案确实取决于您对iphone编程和服务器端编程的了解,以及当前如何设置数据库-但很可能您将需要编写某种允许远程客户端的Webservice / REST API用数据库做事。

There are many frameworks available for that on the server side - if you're starting from scratch, ruby on rails may be a good choice. 服务器端有许多可用的框架-如果您是从头开始的,那么在Rails上使用ruby可能是一个不错的选择。

On the iphone side, you'll probably want to start by reading up on NSURLConnection, and various request/response formats that you can use with it. 在iPhone方面,您可能需要先阅读NSURLConnection以及可以与之一起使用的各种请求/响应格式。 I've found exchanging plists between the phone and server to be a pretty easy approach. 我发现在电话和服务器之间交换主机是一种非常简单的方法。

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

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