Skip to content

Instantly share code, notes, and snippets.

@jakebromberg
Created November 19, 2017 17:24
Show Gist options
  • Save jakebromberg/059b3c70ab547669cd1752f586c6606e to your computer and use it in GitHub Desktop.
Save jakebromberg/059b3c70ab547669cd1752f586c6606e to your computer and use it in GitHub Desktop.
`DataStreamer` class is a `URLSessionDataTask` delegate that logs out incoming data
extension URL {
static var WXYCStream: URL {
return URL(string: "http://audio-mp3.ibiblio.org:8000/wxyc.mp3")!
}
}
class DataStreamer: NSObject, URLSessionDataDelegate {
func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive data: Data) {
dump(data)
}
}
DispatchQueue.global(qos: .background).async {
let session = URLSession(
configuration: URLSessionConfiguration.background(withIdentifier: "Hello"),
delegate: DataStreamer(),
delegateQueue: .current
)
let task = session.dataTask(with: URL.WXYCStream)
task.resume()
}
let group = DispatchGroup()
group.enter()
group.wait()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment