Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

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

Reply
 
LinkBack Thread Tools Display Modes
Old 11-26-2008, 04:32 AM   #1 (permalink)
New Member
 
Join Date: Aug 2008
Posts: 36
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, 11:17 AM   #2 (permalink)
New Member
 
Join Date: Aug 2008
Posts: 36
Default

Anyone?
P-development is offline   Reply With Quote
Old 12-09-2008, 05:48 PM   #3 (permalink)
New Member
 
Join Date: Dec 2008
Location: Hawaii
Posts: 1
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: 158,775
Threads: 89,203
Posts: 380,595
Top Poster: BrianSlick (7,129)
Welcome to our newest member, Andy8888
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 10:50 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0