iOS4 Create Background Timer(iOS4 创建后台定时器)
问题描述
我(基本上)需要在 iOS 4 上创建一个后台计时器,它允许我在经过特定时间后执行一些代码.我读过你可以使用一些 [NSThread detachNewThreadSelector:达到目标:withObject:];
但在实践中它是如何工作的呢?如何确保线程也保留在后台.本地通知不对我有用,因为我需要执行代码,而不是通知用户.
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.
我们将不胜感激!
推荐答案
您可以使用这些调用在新线程 (detachNewThred) 中执行带有某些参数 (withObject) 的对象 (toTarget) 的方法 (选择器).
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 创建后台定时器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:iOS4 创建后台定时器


基础教程推荐
- 如何使用 YouTube API V3? 2022-01-01
- :hover 状态不会在 iOS 上结束 2022-01-01
- “让"到底是怎么回事?关键字在 Swift 中的作用? 2022-01-01
- 如何使 UINavigationBar 背景透明? 2022-01-01
- Android ViewPager:在 ViewPager 中更新屏幕外但缓存的片段 2022-01-01
- 使用 Ryzen 处理器同时运行 WSL2 和 Android Studio 2022-01-01
- Android文本颜色不会改变颜色 2022-01-01
- 固定小数的Android Money Input 2022-01-01
- LocationClient 与 LocationManager 2022-01-01
- 在 iOS 上默认是 char 签名还是 unsigned? 2022-01-01