简体   繁体   English

如何在iOS Swift中的时间间隔上发送HTTP GET请求?

[英]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)

对于swift3,请使用Timer,有关详细信息,请参考间隔发送http请求

Timer.scheduledTimer(timeInterval: 3, target: self, selector: #selector(getMessage), userInfo: nil, repeats: true)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在iOS应用程序的后台发出间歇性的HTTP POST请求-Swift - How to make intermitent HTTP POST requests in the background of an iOS app - Swift 如何在IOS中同时发送N个请求 - How to Send N number of Requests at Same Time in IOS 定期在后台模式下发送 HTTP 请求 (iOS) - Send HTTP Requests in Background Mode (iOS) Periodically 如何获取当前 EST 时间 IOS Swift - How to get Current EST time IOS Swift 如何在Unity中为Android / IOS进行请求并获取HTTP响应代码 - How to do requests in Unity for android/IOS and get HTTP response codes 如何在 swift [iOS] 的特定时间开始发送本地通知 UNTimeInterval - How to send local notification UNTimeInterval starting at specific time in swift [iOS] 如何使用Swift 4 iOS在特定时间间隔内更新用户的后台位置? - How to update background location of user within specific time interval using swift 4 iOS? 如何按时间间隔发送本地推送通知 - How to send local push notifications in a time interval 增加 Firebase HTTPs 可调用 iOS Swift 中的时间间隔 - Increase time interval in Firebase HTTPs Callable iOS Swift 两个时间间隔之间的差异ios组件swift 3 - difference between two time interval ios components swift 3
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM