Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSData to NSString truncated - iPhone

I have the following code.

NSData *pageData = [NSURLConnection sendSynchronousRequest:request returningResponse:NULL error:NULL];
NSString *webpage = [[NSString alloc] initWithData:pageData encoding:NSUTF8StringEncoding];

This works fine with most pages but truncates the really long ones, is there a way around this at all?

like image 595
Lee Armstrong Avatar asked Jul 18 '26 23:07

Lee Armstrong


1 Answers

I believe this is what you are looking for (from the NSString class reference linked above):

stringWithContentsOfURL:encoding:error:

Returns a string created by reading data from a given URL interpreted using a given encoding.

(id)stringWithContentsOfURL:(NSURL *)url encoding:(NSStringEncoding)enc error:(NSError **)error

Parameters
url The URL to read.

enc The encoding of the data at url.

error If an error occurs, upon returns contains an NSError object that describes the problem. If you are not interested in possible errors, you may pass in NULL.

Return Value
A string created by reading data from URL using the encoding, enc. If the URL can’t be opened or there is an encoding error, returns nil.

like image 192
nicktmro Avatar answered Jul 20 '26 17:07

nicktmro