[英]is there any way to Send HTTP Requests in Background Mode (iOS) Periodically?
您好,我正在開發該應用程序,其中我需要每10秒在Http請求中發送一次數據。 當應用程序處於運行狀態時,它可以正常工作,但一旦進入后台或非活動狀態,它將立即停止。
您的應用程序需要支持以下幾點。 如果您的應用程序可以具有后台運行功能,那么您可以做幾件事。
要定期運行,您將需要一個計時器(NSTimer)。 您將需要一種將執行HTTP請求的方法。
Timer.scheduledTimer(timeInterval: 5, target: self, selector: #selector(callWebservice), userInfo: nil, repeats: true)
func callWebservice() {
// Handle response
}
另請參閱: https : //developer.apple.com/library/archive/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.