Does NSURLConnection block the main thread?

后端 未结 2 863
半阙折子戏
半阙折子戏 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.

提交回复
热议问题