Rick de Jong
Rick de Jong

Reputation: 237

Reading text from HTML iOS SDK

I have a Label in my View. The Label's text must be the text on http://sample.com/file.html.

How to do this?

Upvotes: 0

Views: 198

Answers (2)

fguchelaar
fguchelaar

Reputation: 4909

You can 'load' the contents of the URL directly into an NSString:

NSString *text = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://sample.com/file.html"] encoding:NSUTF8StringEncoding error:&error];

And then set the label's text accordingly!

Upvotes: 2

Dan F
Dan F

Reputation: 17732

Try using NSData's

+ (id)dataWithContentsOfURL:(NSURL *)aURL

Then convert to a string with NSString's

- (id)initWithData:(NSData *)data encoding:(NSStringEncoding)encoding

Upvotes: 0

Related Questions