[英]How to send HTTP GET requests on a time interval in ios swift?
How do you continuously send HTTP GET requests on a time interval (every x/seconds)? 如何在一个时间间隔(每x /秒)内连续发送HTTP GET请求?
Currently I have a getMessages() function in my viewDidLoad() so that it will send a GET request on view load and populate a table view with the results from the server. 当前,我的viewDidLoad()中有一个getMessages()函数,以便它将在视图加载时发送GET请求,并使用服务器中的结果填充表视图。
Just use the NSTimer
method scheduledTimerWithTimeInterval
. 只需使用NSTimer
方法scheduledTimerWithTimeInterval
。 You can say that it should repeat the timer and which method should get invoked if the time is over: 您可以说它应该重复计时器,如果时间到了应该调用哪个方法:
NSTimer.scheduledTimerWithTimeInterval(timeInSeconds, target: self, selector: "getMessages", userInfo: nil, repeats: true)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.