简体   繁体   中英

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. 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). You will need a method which will execute the HTTP request.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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