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 创建后台定时器
基础教程推荐
- 为什么姜饼模拟器方向卡在应用程序中? 2022-01-01
- Xcode UIView.init(frame:) 只能在主线程中使用 2022-01-01
- navigationItem.backBarButtonItem 不工作?为什么上一个菜单仍然显示为按钮? 2022-01-01
- iOS - UINavigationController 添加多个正确的项目? 2022-01-01
- Play 商店的设备兼容性问题 2022-01-01
- UIImage 在开始时不适合 UIScrollView 2022-01-01
- 如何比较两个 NSDate:哪个是最近的? 2022-01-01
- SwiftUI-ScrollViewReader的ScrollTo不滚动 2022-01-01
- Android Volley - 如何动画图像加载? 2022-01-01
- 如何将图像从一项活动发送到另一项活动? 2022-01-01
