开发者

IPhone Development - Main Thread

开发者 https://www.devze.com 2023-03-26 06:28 出处:网络
I am new to iPhone development and I would like to ask a question concerning asynchronous events. Supposing I have a NSURLConnection and the correspoding delegate methods ie. didReceiveResponse, did

I am new to iPhone development and I would like to ask a question concerning asynchronous events.

Supposing I have a NSURLConnection and the correspoding delegate methods ie. didReceiveResponse, didFailWi开发者_开发技巧thError etc. The methods are called asynchronously when events are fired. Are all methods executed on the main thread? Or does the iOS create separate threads that execute the corresponding method code?

I am facing some random crashes to my app, and I guess that it is a synchronization issue.


The delegate methods of NSURLConnection are executed in the main thread. That is the whole reason behind being asynchronous, no need to have a separate thread.

About the internals, I/O is an inherently asynchronous world, so I also do not think that internally NSURLConnection uses threading. I suppose that it is the OS that manages the communication in a async way, but I am not sure about it.

Anyway, you can be sure that your delegate methods are executed from within the main thread.

0

精彩评论

暂无评论...
验证码 换一张
取 消