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 12-20-2008, 02:55 PM   #1 (permalink)
Registered Member
 
Join Date: Dec 2008
Location: UK
Posts: 1,886
Default Changing Synchronous to Asynchronous

I'm using this code to download a page to an NSData then convert it to an NSString.
Code:
NSURL *url = [NSURL URLWithString:@"someaddress.com"];
NSError *error;
	
NSMutableURLRequest* liveRequest = [[NSMutableURLRequest alloc] initWithURL:url];
[liveRequest setCachePolicy:NSURLRequestReloadIgnoringCacheData];

//Need a header for something
[liveRequest setValue:@"headervalue" forHTTPHeaderField:@"headerfield"];

//Download the page to an NSData
NSURLResponse* response;
NSData* myData = [NSURLConnection sendSynchronousRequest:liveRequest returningResponse:&response error:&error];

//Convert the data into a string.
NSString * checkResponse = [[NSString alloc] initWithData:myData encoding:NSASCIIStringEncoding];
This locks up the UI so I was wondering how I can change this into an Asynchronous request, keeping the header information and what not.

Thanks,
Tom
harrytheshark is offline   Reply With Quote
Old 12-20-2008, 03:52 PM   #2 (permalink)
Registered Member
 
RickMaddy's Avatar
 
Join Date: Oct 2008
Location: Denver, CO
Posts: 2,122
Default

Look at the docs for NSURLConnection. There is a reference to a document called "URL Loading System". That doc shows you how to do asynchronous connections.
RickMaddy is offline   Reply With Quote
Old 12-20-2008, 04:09 PM   #3 (permalink)
Registered Member
 
Join Date: Dec 2008
Location: UK
Posts: 1,886
Default

Ah Yes! Thanks I've got it working now.

Tom
harrytheshark 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,885
Threads: 89,229
Posts: 380,763
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

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