iPhone 应用程序,在后台应用程序时运行 http 请求 [英] iPhone app, running http requests while application in background

查看:32
本文介绍了iPhone 应用程序,在后台应用程序时运行 http 请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 iPhone 应用程序中,当应用程序在后台.我已经使用 ASIHttpRequest 进行查询,效果很好,但是现在我试图找到一种在后台触发它们的方法.在应用程序委托中,我添加了对发出请求的方法的调用:

In my iPhone app I would like to run several queries when the application is in background. I already use ASIHttpRequest to make the queries, that works fine but now I try to find a way to trigger them in background. In the app delegate, I have added a call to the method making the request:

[self getItemsFromServer]

   [self getItemsFromServer]

getItemsFromServer 运行一个异步请求(在模拟器上我一旦我将应用程序返回到前景).我如何使用某种计时器让此方法每 10 次运行一次分钟(我只需要运行 4 到 5 次,而不是每 10 分钟,直到它回到前台 :-) )?

getItemsFromServer runs an asynchronous request (on the simulator I saw the log of this methods once I get back the application to the foreground). How can I use some kind of timer to have this method ran every 10 minutes (I just need to run it 4 or 5 times, not each 10 minutes until it goes back to foreground :-) )?

非常感谢,

此致,

吕克

推荐答案

iOS4 允许您的应用运行 X 时间,当然,iOS4 授予您请求的时间.查看:在后台完成一个长时间运行的任务.

iOS4 allows your app to run for X amount of time, granted that iOS4 grants you the time you request. Check out: Completing a Long-Running Task in the Background.

具体来说,

在暂停之前的任何时候,应用程序都可以调用 beginBackgroundTaskWithExpirationHandler: 方法向系统请求额外的时间在后台完成一些长时间运行的任务.如果请求被批准,并且如果应用程序在任务进行时进入后台,系统会让应用程序运行额外的时间而不是暂停它

Any time before it is suspended, an application can call the beginBackgroundTaskWithExpirationHandler: method to ask the system for extra time to complete some long-running task in the background. If the request is granted, and if the application goes into the background while the task is in progress, the system lets the application run for an additional amount of time instead of suspending it

这篇关于iPhone 应用程序,在后台应用程序时运行 http 请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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