So I have had extensive experience reading rendered html source code of a website in Java. However I have researched thoroughly regarding how to do the exact same thing in Objective-C and have been able to come up with a solution that should work, but it doesn't. The idea is that i want to read each line, for example:"view-source:www.apple.com", i want the read the result of that page line by line. I don't want any Html parser etc. This is what i have:
NSString *s = [NSString stringWithFormat:@"http://www.apple.com"];
NSURL *url = [NSURL URLWithString:s];
NSInputStream *iStream= [[NSInputStream alloc] initWithURL:url];
[iStream setDelegate:self];
[iStream scheduleInRunLoop:[NSRunLoop currentRunLoop]
forMode:NSDefaultRunLoopMode];
[iStream open];
NSLog(@"stream successfully opened");
NSInteger result;
uint8_t buffer[1024];
while((result = [iStream read:buffer maxLength:1024]) != 0) {
if(result > 0) {
NSLog(@"Buffer is %@",buffer);
// buffer contains result bytes of data to be handled
} else {
NSLog(@"ERROR: %@",buffer);
// The stream had an error. You can get an NSError object using [iStream streamError]
}
NSLog(@"end of while loop: %@",buffer);
}
// Either the stream ran out of data or there was an error
NSLog(@"Either the stream ran out of data or there was an error");
This runs and compiles fine, but the result is always 0. Again i have done a a lot of research and i don't understand why the result is 0. Any help is appreciated.