如何创建线程来检查时间? [英] How to create thread to checking time?
问题描述
我必须设置时间每天检查两次服务器中的更新数据,假设是上午9点和晚上9点,但是我不知道这样做的方式.
I have to setting a time to check for update data from server 2times a day, suppose 9AM and 9PM, but i don't know the way to do that.
创建一个线程,每次运行并通过设置检查当前时间,如果它们相等,那么任务呢?这样好吗?我认为那是糟糕的表现.
Create a thread, run every-time and check time current time with setting,if they are equal,so do task? This way is good? I think that's bad performance.
推荐答案
使用线程,但是如果相等,则不要每秒钟检查一次.您可以使用NSNotification.当时间相同时,它将发送一条通知以获取数据.
Use thread but instead of checking every sec, if it is equal. You could use NSNotification. When the time is the same, it will send a notification to get the data.
您可以阅读以下内容: iOS定时后台处理
You can read this: iOS timed background processing
也可以阅读本教程: http://mobile.tutsplus.com/tutorials/iphone/ios-multitasking-local-notifications/
我也正在阅读.对我来说也有些新事物.最好的是NSLocalNotifications.看看这个:提醒应用
I have reading up as well. Something new for me as well. Best is NSLocalNotifications. Have a look at this: Reminder App
本地通知的文档:本地通知
这篇关于如何创建线程来检查时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!