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()
}
そして、あなたはそれが本当にタスクは時間がかかりますどのくらいに依存
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()
})
}
[Swift - NSURLSessionのバックグラウンドでのダウンロードは可能ですか?](http://stackoverflow.com/questions/33503164/swift-nsurlsession-downloading-in-background) –
この質問を見ることもできます:http ://stackoverflow.com/questions/40395810/downloading-in-background-and-waking-app-when-finished/40395988#40395988 – pbodsk