简体   繁体   English

有什么办法可以在后台模式(iOS)中定期发送HTTP请求?

[英]is there any way to Send HTTP Requests in Background Mode (iOS) Periodically?

Hello I am developing the Application in which i need to send Data in Http request every 10 seconds. 您好,我正在开发该应用程序,其中我需要每10秒在Http请求中发送一次数据。 it's working fine when app is in running state but it will stop as soon as it will goes in background or inactive state. 当应用程序处于运行状态时,它可以正常工作,但一旦进入后台或非活动状态,它将立即停止。

Your app need to support a couple of things. 您的应用程序需要支持以下几点。 If your app can have the background-running capability then you can do a couple of things. 如果您的应用程序可以具有后台运行功能,那么您可以做几件事。

To run periodically you will need a Timer (NSTimer). 要定期运行,您将需要一个计时器(NSTimer)。 You will need a method which will execute the HTTP request. 您将需要一种将执行HTTP请求的方法。

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

func callWebservice() {
  // Handle response 
}

Also please refer : https://developer.apple.com/library/archive/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html 另请参阅: https : //developer.apple.com/library/archive/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM