 |
 |
|
 |
11-26-2008, 03:32 AM
|
#1 (permalink)
|
|
New Member
Join Date: Aug 2008
Posts: 36
|
Wrapping asynchronous code in a synchronous method call
Hi,
I wonder how I would go about wrapping some aSynchronous code into a synchronous method call, like the NSURLConnection sendSynchronousRequest:returningResponse:error: method. It wraps the aSynchronous NSURLConnection code into this synchronous method. I'd like to do this do because I need to alter some of the delegate methods of NSURLConnection, but I do need it to be synchronous.
How would I do this? Or, in general, how could I block the calling thread until I notify it?
Thanks in advance.
|
|
|
11-27-2008, 10:17 AM
|
#2 (permalink)
|
|
New Member
Join Date: Aug 2008
Posts: 36
|
Anyone?
|
|
|
12-09-2008, 04:48 PM
|
#3 (permalink)
|
|
New Member
Join Date: Dec 2008
Location: Hawaii
Posts: 1
|
synchronously using NSURLConnection's asynchronous delegate methods
There is a way to use NSURLConnection's delegate methods synchronously. However, unless you know about how NSRunLoop works, it's not quite straightforward.
In general, you'll want to create the NSURLConnection and _not_ have it start immediately. Instead, you should schedule NSURLConnection to run in its own run mode in the current NSRunLoop, then start the connection. You should then spin the run mode in the current NSRunLoop until the delegate method flags that the connection has finished loading (or failed loading). After which, you can continue on w/ the rest of your application.
If you want code and a more complete description, there's a blog post about it here:
Using NSURLConnection Synchronously via Asynchronous Delegates | stackq
-Kelvin
|
|
|
 |
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
» Advertisements |
» Online Users: 576 |
| 42 members and 534 guests |
| AdvertiseSpace, AlanD, Angerika, AppStoreHQ, beginer2007, BrianSlick, CHV, craig.w, damienbern, demiandenker, Digiguy, dre, drewse, eduardcasagolda, fiftysixty, freakybee, funky, Giga, gstriph, hawksz, icordoba, iGeorG, iphonedave, Johanovski, JohnnyC, jurosik, ke888le, Lukapple80, maccoykung, orange_dot, rawjam, RobotWoods, rocksing2010, Rudy, SalvoMaltese, sle39lvr, smasher, umarmara, walkman2001, Zoid, _nivek |
| Most users ever online was 779, 05-11-2009 at 09:55 AM. |
» Stats |
Members: 24,370
Threads: 39,163
Posts: 171,679
Top Poster: smasher (2,579)
|
| Welcome to our newest member, Giga |
|