建议从Web服务器获取数据? [英] Suggestion for getting data from a web server?

查看:215
本文介绍了建议从Web服务器获取数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网络服务器,其中包含有趣的位置列表。这些是在Web服务器上的硬编码,并由服务器端的管理员维护。用户无法添加或删除任何内容。

I have a web server which contains a list of "interesting locations". These are "hard coded" on the web server, and maintained from an administrator on the server-side. Users can't add or remove anything.

从我的应用程序中,我想创建一个按钮提取位置,然后应用程序应与Web服务器和请求有趣的位置列表。

From within my app, I want to make a button "fetch locations", and the app should then contact the web server and ask for that "interesting locations" list.

我使用Core Data并在我的模型中有一个InterestingLocation实体。目标是从网络服务器获取数据,并使用Core Data将其保存在设备上,以便即使没有互联网连接也可访问。

I'm using Core Data and have an InterestingLocation entity in my model. The goal is to get the data from the web server and persist it on the device with Core Data, so that it is accessible even without internet connection.

我的想法是在服务器端使用XML,并在XML文件中输出InterestingLocationobjects。

My idea was to use XML on the server side and output the InterestingLocation "objects" in an XML file. There are about 100 of them only, so not really huge.

在客户端(设备),也许是XML-RPC?

On the client side (device), maybe XML-RPC?

对于某些建议和进一步的信息,您会对哪里/如何开始感到高兴:)

Would be happy about some suggestions and further information where/how to get started :)

推荐答案

保持简单。在服务器端,使用 RESTful原则使界面尽可能简单。

My advice is keep it simple. On the server side, use RESTful principles to make the interface as simple as possible.

然后,您需要在您的iPhone应用程序中执行的操作是使用 NSURLConnection 以获取网址。 NSURLConnection 是从远程位置下载文件的非常好的异步方式。

Then, all you'll need to do in your iPhone app is use an NSURLConnection to fetch the URL. NSURLConnection is a very nice, asynchronous way of downloading files from remote locations.

解析XML或JSON并创建相应的Core Data对象。我通常喜欢在单独的线程中的单独的托管对象上下文中执行这样的导入操作。保存受管对象上下文时,使用 NSManagedObjectContextDidSaveNotification 将更改与您的主要受管对象上下文合并。

After that, it's a simple matter of parsing the XML or JSON and creating the appropriate Core Data objects. I generally like to do import operations like this on a separate managed object context in a separate thread. When you save the managed object context, use the NSManagedObjectContextDidSaveNotification to merge in the changes with your main managed object context.

这篇关于建议从Web服务器获取数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆