swift - Completing webservice in background state iOS -


is there possible way complete webservice task when ios application goes background state using urlsession ? not trying upload huge sized file server , instead trying upload 4 digit key. have tried below method background task.

var bgtask = uiapplication.shared.beginbackgroundtask(expirationhandler: {}) 

for testing purpose , calling webservice in loop , logged. when go background mode webservice calls getting stuck.

class func generalpost(url: string, postcompleted : (response: string) -> ()) {         let request = nsmutableurlrequest(url: nsurl(string: url)!)         let session = nsurlsession.sharedsession()         request.httpmethod = "post"         let datastring = ""          request.httpbody = datastring.datausingencoding(nsutf8stringencoding)          let task = session.datataskwithrequest(request, completionhandler: {data, response, error -> void in              let strdata = nsstring(data: data!, encoding: nsutf8stringencoding)                                   postcompleted(response: strdata)                           })         task.resume()     } 

and can use

 generalpost(url: "http://stackoverflow.com/") { (response) in             dispatch_async(dispatch_get_main_queue(), { () -> void in                 uialertview(title: "message", message: response, delegate: nil, cancelbuttontitle: "ok").show()                             })         } 

Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -