views:

2413

answers:

5

I found a tutorial on the net that uses the stringWithContentsOfURL command that is now deprecated as of iPhone OS 3.0. However I can't find out what I'm meant to use instead, and how to implement it.

Below is the code surrounding the stringWithContentsOfURL line in case you need it for reference.

NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&output=csv", 
     [addressField.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSString *locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString]];
NSArray *listItems = [locationString componentsSeparatedByString:@","];

Thanks.

+8  A: 

It has been replaced with stringWithContentsOfURL:encoding:error: or stringWithContentsOfURL:usedEncoding:error:.

Greg Martin
+8  A: 

Thanks Greg, but for all those other beginners here is an example

NSError* error;
NSString* text = [NSString stringWithContentsOfURL:TheUrl encoding:NSASCIIStringEncoding error:&error];
if( text )
{
    NSLog(@"Text=%@", text);
}
else 
{
    NSLog(@"Error = %@", error);
}
bstoney
A: 

Thank you Greg and bstoney, your answers together helped me solve my warnings.

Ariel Rivera
A: 

The net is crowded with examples and snippets that either is half-finished, not tested or outdated.

THIS ONE WAS THE END OF MY 2 DAYS JOURNEY TO GET THE NEW VERSION OF "stringWithContentsOfUR" CORRECT :)

Thank you "bstoney", so simple and works 100%, you're my hero !

And to Greg Martin: That one took me just a second to find out, but how to implement the new version in my old code was my problem. Thank's still, after all you did post at all :)

Wedoe
A: 

For anything more than trivial, I recommend ASIHTTPRequest:

http://allseeing-i.com/ASIHTTPRequest/

Andrew Kuklewicz