Home News Forum Social Networking Support Us Advertise

Spanish Lesson 1 ($1.99)

aWake!Gently ($1.99)

The Bird & The Snail - Knock Knock - Deluxe ($4.99)

Match-It Trains ($0.99)

Tangled ($0.99)

iFlatter ($0.99)

The 15 puzzle ($0.99)

Tap Forms Database ($8.99)

Higher or Lower Card Game (Hi Lo) ($0.99)

Red Pixel ($0.99)

Time-Shift Radio ($0.99)

Want your application advertised here? Only $10/week!

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 11-26-2008, 03:32 AM   #1 (permalink)
Member
 
Join Date: Aug 2008
Posts: 36
Rep Power: 0
P-development is on a distinguished road
Default 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.
P-development is offline   Reply With Quote
Old 11-27-2008, 10:17 AM   #2 (permalink)
Member
 
Join Date: Aug 2008
Posts: 36
Rep Power: 0
P-development is on a distinguished road
Default

Anyone?
P-development is offline   Reply With Quote
Old 12-09-2008, 04:48 PM   #3 (permalink)
Junior Member
 
Join Date: Dec 2008
Location: Hawaii
Posts: 1
Rep Power: 0
kelvin is on a distinguished road
Default 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
kelvin is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


» Advertisements


» Stats
Members: 8,229
Threads: 20,197
Posts: 90,213
Top Poster: RickMaddy (2,121)
Welcome to our newest member, jrsiqueira
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:21 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0