Created
September 29, 2018 23:35
-
-
Save regularberry/b9ed7e7429947bd217ec7af9280c19ff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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