xcode 如何创建像 iPhone 应用这样每周更新的新闻
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9350386/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to create a news like iPhone app that updates weekly
提问by Justin Heather Barrios
I have created a few small apps for the iPhone so I have some experience. An organization that I'm in asked me if I could program a weekly newsletter app for them. I though it would be a good challenge so I agreed. My question is: how do I get the app to update weekly without the users having to re-download or manually update? Do I connect to a database or a website? Can anyone send me the link to a good tutorial? I wasn't able to find one.
我为 iPhone 创建了一些小应用程序,所以我有一些经验。我所在的一个组织问我是否可以为他们编写每周通讯应用程序。我认为这将是一个很好的挑战,所以我同意了。我的问题是:如何让应用程序每周更新,而无需用户重新下载或手动更新?我是连接到数据库还是网站?谁能给我一个好的教程的链接?我找不到一个。
Thank you!
谢谢!
回答by Lorenzo B
Your question is very general but I could give you some suggestions.
你的问题很笼统,但我可以给你一些建议。
First, you need to connect to a service that provides you news info. This is needed. The service could send you an xml that you can parse and display, for example in a UITableView
. XML is not the only solution. You could use also JSON.
首先,您需要连接到为您提供新闻信息的服务。这是需要的。该服务可以向您发送一个 xml,您可以对其进行解析和显示,例如在 .xml 文件中UITableView
。XML 不是唯一的解决方案。您也可以使用 JSON。
For parsing XML I suggest you to read GDataXML, while for JSON JSONKit framework. But there are also other valid framework out there.
对于解析 XML,我建议您阅读 GDataXML,而对于 JSON JSONKit 框架。但也有其他有效的框架。
Then, to save data it depends on what kind of data you deal with. Here you could find different ways to save your news. Save an XML that contains your news, serialize data and save them in the local filesystem or use Core-Data.
然后,要保存数据取决于您处理的数据类型。在这里,您可以找到不同的方式来保存您的新闻。保存包含新闻的 XML,序列化数据并将它们保存在本地文件系统中或使用 Core-Data。
To update your news without user actions, you have to save the last time when the app has downloaded news (for example in NSUserDefaults
) and each time time the application is "activated" check for that date and update news if necessary.
要在没有用户操作的情况下更新您的新闻,您必须保存应用程序下载新闻的最后时间(例如在NSUserDefaults
),并且每次“激活”应用程序时检查该日期并在必要时更新新闻。
Out there there are plenty of tutorials on how to (in parenthesis I inserted classes or framework that you could have a look):
有很多关于如何操作的教程(在括号中,我插入了您可以查看的类或框架):
- consuming web service on iPhone (ASIHttpRequest - no more supported,
NSURLConnection
class, AFNetworking) - dealing with XML file/data and theirs parsing (GDataXML, touchXML, etc.)
- dealing with JSON messages (JSONKit, etc.)
- managing documents (
NSFileManager
class) - using Core-Data
- using Property-List and/or
NSUserDefaults
- 在 iPhone 上使用 Web 服务(ASIHttpRequest - 不再受支持,
NSURLConnection
类,AFNetworking) - 处理 XML 文件/数据及其解析(GDataXML、touchXML 等)
- 处理 JSON 消息(JSONKit 等)
- 管理文件(
NSFileManager
类) - 使用核心数据
- 使用属性列表和/或
NSUserDefaults
First three cover the first step (download). Other three cover the second one (save). Obviously you have not to use all of them. For example a configuration could be:
前三个涵盖了第一步(下载)。其他三个覆盖第二个(保存)。显然,您不必使用所有这些。例如,配置可以是:
NSURLConnection
for service, GDataXML for parsing XML data and Property-List for save data.
NSURLConnection
用于服务,GDataXML 用于解析 XML 数据,Property-List 用于保存数据。
Hope it helps.
希望能帮助到你。
回答by Peter M
A simpler approach would be to make it a pure web app and update the website weekly.
一种更简单的方法是使其成为纯网络应用程序并每周更新网站。
Your content providers are going to have to do those updates anyway.
无论如何,您的内容提供商将不得不进行这些更新。