Asynchronous NSURLConnection with NSOperation

后端 未结 3 1318
逝去的感伤
逝去的感伤 2020-12-02 23:42

I want to do NSURLConnection in background mode,because it response is having much data.Forums are telling to use Apple\'s finite length coding to use in

相关标签:
3条回答
  • 2020-12-03 00:22

    This kind of question was asked a zillion time. Delegates are not getting called because as of iOS 4 operations are started on a secondary thread. The thread probably exits before the delegates are called that's all.

    Keep the connection on the main thread and handle the data in a background thread using GCD.

    I'v wrote about all this stuff here : http://cocoaintheshell.com/2011/04/nsurlconnection-synchronous-asynchronous/

    EDIT : Updated link.

    0 讨论(0)
  • 2020-12-03 00:27

    Look at the sendAsynchronousRequest:queue:completionHandler: method documented here in Apple's Documentation. It allows asynchronous requests with NSURLConnection.

    Note this requires iOS5 or higher

    0 讨论(0)
  • 2020-12-03 00:41

    Apple provides QHTTPOperation, which does just what you want, encapsulates an NSURLConnection within an NSOperation, for a single request. You can find it in Apple's sample code.

    QHTTPOperation is actually a subclass of QRunLoopOperation which lets you encapsulate logic which depends on run-loop callbacks in an NSOperation.

    The 3rd party ASIHTTPRequest is a similar popular solution, AFAIK it is no longer maintained though.

    0 讨论(0)
提交回复
热议问题