Guest User

Untitled

a guest
Dec 14th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 1.18 KB | None | 0 0
  1. fun main(args: Array<String>) {
  2.     autoreleasepool {
  3.         runApp("https://feeds.feedburner.com/kotlin")
  4.     }
  5. }
  6.  
  7. private fun runApp(url: String) {
  8.     println("runApp called")
  9.  
  10.     val session = NSURLSession.sessionWithConfiguration(
  11.         NSURLSessionConfiguration.defaultSessionConfiguration(),
  12.         object : NSObject(), NSURLSessionDataDelegateProtocol {
  13.             override fun URLSession(session: NSURLSession, dataTask: NSURLSessionDataTask, didReceiveResponse: NSURLResponse, completionHandler: (NSURLSessionResponseDisposition) -> Unit) {
  14.                 println("didReceiveResponse called")
  15.  
  16.                 completionHandler(NSURLSessionResponseAllow)
  17.             }
  18.             override fun URLSession(session: NSURLSession, dataTask: NSURLSessionDataTask, didReceiveData: NSData) {
  19.                 println("didReceiveData called")
  20.             }
  21.             override fun URLSession(session: NSURLSession, task: NSURLSessionTask, didCompleteWithError: NSError?) {
  22.                 println("didCompleteWithError called")
  23.             }
  24.         },
  25.         delegateQueue = NSOperationQueue.mainQueue()
  26.     )
  27.     session.dataTaskWithURL(NSURL(URLString = url)).resume()
  28. }
Advertisement
Add Comment
Please, Sign In to add comment