iOS的定时后台处理 [英] iOS timed background processing

查看:156
本文介绍了iOS的定时后台处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我的应用程序能 - 说,每12小时 - 即使该应用程序是不是有curently运行或在后台,发送一个HTTP请求到服务器,得到一个小文件,版本号,并且如果服务器上的版本比在客户端上的版本越高,则更多的文件下载到磁盘中,以便在下一次该应用启动时,它会发现在磁盘上的新内容。

I'd like my app to be able to - say, every 12 hours - even if the app isn't curently running or is in the background, send an HTTP request to a server, get a small file with a version number and if the version on the server is higher than the version on the client, then download some more files to disk so that next time the app starts it will find new content on disk.

什么设​​计模式最适合在IOS这样的任务呢?

What design patterns are best suited for such task in ios?

几个来我的心,但我没有经历过。

A few come to my mind but I'm not as experienced.


  1. 也许推送通知,服务器需要推一个消息给所有的客户时,有可用的新版本。

  2. 或者,是否有类似Android的服务的东西,可以帮助?

  3. 或者,也许每一个应用程序启动时(或转到前台)时间刚刚ping服务器,看看是否有什么新的。

  4. 或者,每次应用程序启动时ping服务器,再加上添加一个定时器的情况下,接下来的12小时这个程序仍然会在前台。

  5. 或者,每一个应用程序启动时,检查preference值,如果服务器被ping最后的时间超过12小时前,那么现在ping到它。然后保存这个平的时间。

  1. Perhaps push notifications, the server needs to push a message to all clients when there's a new version available.
  2. Or, Is there something similar to Android's Service that can help?
  3. Or, maybe every time the app starts (or goes to the foreground) just ping the server and see if there's anything new.
  4. Or, every time the app starts ping the server plus add a timer for the next 12h in case this app will still be in the foreground.
  5. Or, every time the app starts, check a preference value and if the last time the server was pinged was more than 12h ago, then ping it now. And then save this ping time.

选项1可以在服务器上更重,可能是更复杂的实现(考虑一个IOS newbe),但可能是真正的后台更新的唯一选择。但即便如此,我还是不希望用户有一些低级别的数据更新B / WA客户端和服务器的反应(这就是它是什么),因此除非推送通知可直接进入应用程序,并执行一些没有用户的干预,那么这个选项不飞了。结果
选项​​3-5都是可能的,不健全的太辛苦,但是当应用程序在前台,他们只会工作。

Option 1 may be more heavy on the server and could be more complicated to implement (consider an ios newbe) but may be the only option for real background update. But even so, I still don't want the user to have to react to some low-level data update b/w a client and a server (and that's what it is), so unless push notifications can go directly to the app and execute something without the user's intervention then this option doesn't fly.
Options 3-5 are all possible and don't sound too hard but they would only work while the app is in the foreground.

据我所知,后台应用只能无论是播放音乐,获得位置更新或VoIP更新。甚至还有这个破解与沉默的声音,试图摆脱这种限制。 (而没有获得批准的商店)。

From what I know, background apps can only either play music, get location updates or voip updates. There's even this hack with the silent sound that was trying to escape this limitation. (and was not approved to the store).

也许,在地方的限制是正当理由,让我怎么遵守游戏规则,并能够实现定期服务器的ping(或者更一般地说,B /解决周期同步的问题瓦特客户端和服务器,即使应用程序在BG)?

Perhaps the limitations in place are of good cause, so how do I play by the rules and be able to achieve a periodic server ping (or more generally, solve the problem of periodic sync b/w clients and servers even when apps are in bg)?

感谢

推荐答案

我没有你的问题一个明确的答案,只是一个散漫组注释,可以帮助你决定​​什么工作最适合你的情况。对不起,这是我能提供的最好的。

I don't have a definite answer for your question, just a rambling set of comments that may help you decide what will work best for your situation. Sorry, this is the best I can offer.

有一点要记住的是,应用程序不应该使用任何手机的数据计划配额,而不让用户知道它的下载东西。有些应用程序都是关于下载的东西,如Twitter客户端,所以应用程序的性质,告诉应用程序使用数据计划的用户。其他应用,如绘图程序,有一点下载需要明确的,所以应该通知的需要下载用户。

One thing to keep in mind is that an app shouldn't use any of the phone's data-plan quota without letting the user know it's downloading something. Some apps are all about downloading stuff such as Twitter clients, so the nature of the app tells the user the app is using the data plan. Other apps, like a drawing program, have little explicit need for downloading, so should notify the user of a need for a download.

由于苹果不允许开发者在后台下载的选项,使用的是iOS人进行培训,等待他们的应用程序下载更新的数据。典型的方式来改善用户体验,同时等待下载到至少秀微调,让用户知道应用程序正在工作。为了进一步改善界面,发送下载到另一个线程,并允许人们继续使用该应用程序的其余部分。它们可以与旧的数据进行交互,或者使用的应用程序中没有的需要更新的部分。

Because Apple doesn't allow developers the option of downloading in the background, people using iOS are trained to wait for their apps to download updated data. The typical way to improve the user experience while waiting for a download is to at a minimum show a spinner, letting the user know the app is working. To improve the interface even more, send the download to another thread, and allow the people to continue to use the rest of the app. They can interact with the old data, or use the parts of the app that are not in need of an update.

苹果不给程序员的机制在后台最类型的应用程序下载新的内容。根据苹果的产品发布,iOS 5中的书报亭功能将允许订阅在后台更新。也许在将来,我们的开发人员将有后台下载更多的选择。

Apple doesn't give programmers a mechanism to download new content in the background for most app types. According to Apple's announcements, iOS 5's Newsstand feature will allow subscriptions to be updated in the background. Maybe in the future we developers will have more options for background downloading.

我有一个使用方法5应用商店一个应用程序,另外在作品中使用方法3。

I have one app on the app store that uses method 5, and another in the works that uses method 3.

我会使用推送通知(方法1)如果人会希望尽快有新数据可用知道。这将取决于话题。

I'd use push notifications (method 1) if the people would want to know as soon as possible that new data is available. It would depend upon the topic.

iOS不具备像Android的任何服务(方法2)

iOS doesn't have anything like Android's service (method 2)

我有,每个应用程序启动时(方法3)检查RSS供稿的新闻应用程序。这个程序主要是做其他的事情,但显示的起始视图的饲料。由于应用程序是一个简单的工具,帮助人们找到具体的解决办法,RSS提要是辅助。

I have an app that checks an RSS feed for news each time the app is launched (method 3). This app mostly does other things, but shows the feed on the starting view. Since the app is a simple utility that helps people find a specific solution, the RSS feed is ancillary.

我喜欢的方法4.定时器的主意,如果你想给的人一个机会,批准下载,计时器会弹出一个警告视图,然后等待。这样,应用程序实际上不会下载的东西如果设备刚出坐在一起在前台您的应用程序。

I like the timer idea in method 4. If you want to give the person a chance to approve the download, the timer could pop up an alert view, and then wait. That way the app doesn't actually download something if the device was just left sitting with your app in the foreground.

我在我现有的应用程序实现方法5具有一个小的变化。它下载的只是众多视图之一的数据。各该视图被访问时将检查对存储的时间,看看它是否应该下载新的数据。然后,它会要求得到允许。

My implementation of method 5 in my currently available app has a little variation. It downloads the data for just one of many views. Each time this view is visited it checks against the stored time to see if it should download fresh data. Then it asks for permission.

这篇关于iOS的定时后台处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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