iOS4创建后台计时器 [英] iOS4 Create Background Timer

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

问题描述

我(基本上)需要在iOS 4上创建一个后台计时器,这将允许我在经过特定时间后执行一些代码。我已经读过你可以使用一些 [NSThread detachNewThreadSelector:
toTarget:
withObject:];
来实现这个目的但是这在实践中如何运作?如何确保线程也保留在后台。本地通知将 NOT 为我工作,因为我需要执行代码,而不是通知用户。

I (Basically) need to create a background timer on iOS 4 that will allow me to execute some code when a specific amount of time has passed. I have read that you can accomplish this using some [NSThread detachNewThreadSelector: toTarget: withObject:]; but how does that work in practice? How can I ensure that the thread remains in the background also. Local notifications will NOT work for me, as I need to execute code, not notify the user.

帮助将不胜感激!

推荐答案

您可以使用这些调用在新线程中使用某个参数(withObject)执行对象(toTarget)的方法(选择器) (detachNewThred)。

You can use those call to execute a method (selector) of an object (toTarget) with some parameter (withObject) in a new thread (detachNewThred).

现在,如果你想执行延迟任务可能是最好的方法是 performSelector:withObject:afterDelay:以及如果你想在后台运行任务,请调用 detachNewThreadSelector:toTarget:withObject:

Now if you want to execute a delayed task may be the best approach is performSelector: withObject: afterDelay: and the if you want to run the task on background call the detachNewThreadSelector: toTarget: withObject:

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

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