Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Connection: NSObject, URLSessionDataDelegate {
- lazy var session: URLSession = {
- URLSession(configuration: URLSessionConfiguration.default, delegate: self, delegateQueue: nil)
- }()
- func start() {
- let baseURL = ""
- let keyID = ""
- let url = URL(string: "\(baseURL)/v2/path/\(keyID)")!
- var urlRequest = URLRequest(url: url)
- urlRequest.setValue("application/x-ndjson", forHTTPHeaderField: "Accept")
- let tasks = session.dataTask(with: urlRequest)
- tasks.resume()
- }
- func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive data: Data) {
- print("ReceivedData: \(data) - \(String(data: data, encoding: .utf8))") //But since it's chunk, the conversion to String might fail
- }
- func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) {
- print("didComplete withError: \(error)")
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement