iPhone 网络

发布于 2024-08-01 22:09:32 字数 60 浏览 3 评论 0 原文

如果我制作了一个应用程序,我将如何使其与我的服务器上的数据库进行交互? 我有点迷失了,不知道从哪里开始。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

最冷一天 2024-08-08 22:09:32

您可以尝试 Apple 的 “网络和 Internet 入门”< /a> 或 “URL 加载系统简介” ,除了 网络 部分。 ADC 的 iPhone 部分中还有几个处理各种类型网络的示例应用程序。

此外,还有许多​​开源 iPhone 应用程序那里处理网络,包括我自己的

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. There are also several sample applications that handle networking of various types within the ADC's iPhone section.

Additionally, there are a number of open source iPhone applications out there that handle networking, including my own.

若水微香 2024-08-08 22:09:32

我有一个关于 Rails 应用程序的类似问题 - 那里的答案可能会对您有所帮助。

什么是最好的为 Rails 应用程序构建 iPhone 客户端的方法?

但答案实际上取决于您对 iPhone 编程和服务器端编程的了解,以及您目前的数据库设置方式 - 但很可能您会需要编写某种 Web 服务/REST API,允许远程客户端对您的数据库执行操作。

在服务器端有许多可用的框架 - 如果您从头开始,Ruby on Rails 可能是一个不错的选择。

在 iPhone 方面,您可能需要首先阅读 NSURLConnection 以及可以使用它的各种请求/响应格式。 我发现在电话和服务器之间交换 plist 是一种非常简单的方法。

I had a similar question regarding a rails app - the answers there may help you.

What is the best approach for building an iphone client for a rails app?

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.

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.

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. I've found exchanging plists between the phone and server to be a pretty easy approach.

岛徒 2024-08-08 22:09:32

模糊的问题会产生模糊的答案。

这完全取决于您需要什么样的交互。 很多不断的查询? 很少而且很远? 客户端缓存? 实时更新? 所有这些问题都会影响答案。

最简单的方法是使用基于 AJAX 风格的 HTTP 客户端/服务器类型的交互。 将数据库放在网络服务器后面已经被做过无数次了,因此,您会发现很多很多的例子,甚至通过一些谷歌搜索就可以找到解决方案。

您实际上并不需要使用 JavaScript(AJAX 中的 J)。 相反,发送封装您的查询的 HTTP 请求,并让服务器使用包含答案的 XML 文档进行响应。

如果这对您不起作用——开销太大、需要中继二进制信息(XML 很糟糕)等等——那么您将希望更直接地访问数据库。 这更加困难,范围包括从将客户端库移植到 iPhone 到创建您自己的有线协议。

这是一个非常困难的问题,您必须处理网络问题——防火墙、NAT、代理等……这些问题通常已经通过 HTTP 解决了。

坚持使用 HTTP,直到证明它不起作用。 简单多了。

在 iPhone 文档中搜索“http 请求”。 包括 HTTP 客户端 API。

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. 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.

You don't really need to use JavaScript (the J in AJAX). Instead, send over an HTTP request that encapsulates your query and have the server respond with an XML document containing the answer.

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. That is harder and can range from porting a client library to the iPhone to creating your own wire protocol.

A significantly harder problem and you'll have to deal with networking issues -- firewalls, NAT, proxies, etc... -- that are generally already solved with HTTP.

Stick with HTTP until you prove that it won't work. Much simpler.

Search for "http request" in the iPhone docs. HTTP client APIs are included.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文