Does NSURLConnection block the main thread?

后端 未结 2 864
半阙折子戏
半阙折子戏 2020-12-06 02:45

I\'m using NSURLConnection in an iPhone application and the interface seems to slow down after sending initWithRequest: to my NSURLConnection

相关标签:
2条回答
  • 2020-12-06 03:12

    NSURLConnection supports two modes of operation: asynchronous and synchronous. Neither uses separate threads at all. They both use just one thread, that being whatever thread you run them in.

    In synchronous mode, NSURLConnection will block whatever thread you run it in. Asynchronous mode uses the run loop to behave (from the developer's perspective) similarly to a background thread but with lower overhead and without any thread-safety issues. If using asynchronous mode, you want to run it in the main thread. It won't block anything.

    If your interface is slowing down, that is not consistent with using NSURLConnection synchronously, which would instead cause your interface to stop completely until the request is complete.

    0 讨论(0)
  • If you follow apples example on NSURLConnection the call will be handled in a different thread than the main thread.

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