Skip to content

Instantly share code, notes, and snippets.

@regularberry
Created September 29, 2018 23:35
Show Gist options
  • Save regularberry/b9ed7e7429947bd217ec7af9280c19ff to your computer and use it in GitHub Desktop.
Save regularberry/b9ed7e7429947bd217ec7af9280c19ff to your computer and use it in GitHub Desktop.
class ViewController: UIViewController, URLSessionTaskDelegate {
override func viewDidLoad() {
super.viewDidLoad()
let url = URL(string: "http://0.0.0.0")!
let data = "Secret Message".data(using: .utf8)!
let tempDir = FileManager.default.temporaryDirectory
let localURL = tempDir.appendingPathComponent("throwaway")
try? data.write(to: localURL)
let request = URLRequest(url: url)
let config = URLSessionConfiguration.background(withIdentifier: "uniqueId")
let session = URLSession(configuration: config, delegate: self, delegateQueue: nil)
let task = session.uploadTask(with: request, fromFile: localURL)
task.resume()
}
func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) {
print("We're done here")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment