Created
November 19, 2017 17:24
-
-
Save jakebromberg/059b3c70ab547669cd1752f586c6606e to your computer and use it in GitHub Desktop.
`DataStreamer` class is a `URLSessionDataTask` delegate that logs out incoming data
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
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