Object-C: initWithContentsOfURL returning null

Posted by AragornSG on Stack Overflow See other posts from Stack Overflow or by AragornSG
Published on 2010-05-02T13:12:28Z Indexed on 2010/05/02 13:18 UTC
Read the original article Hit count: 233

Hey!

I'm working on an app that would display a remote html and use local images, so what I'm trying to do is download the HTML of the website and display it as a "local" page, that would have access to images in my bundle.

For some reason I can't get initWithContentsOfURL to work. I checked all manuals and examples I could find and it seems that I'm doing it correctly, but the thing just won't work, returns null all the time. The same page loaded with NSURLRequest requestWithURL works fine. Appreciate your help!

Here is the code:

- (void)awakeFromNib 
{
    appURL = @"http://dragontest.fantasy-fan.org";
    notConnectedHTML = @"Could not connect.";

    NSString *seedString = [[NSString alloc] initWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/seed.php", appURL]]];

    NSString *HTMLdata = @"";

    if (seedString = @"(null)") {
        NSLog(@"Can't connect on awakeFromNib.");
        HTMLdata = notConnectedHTML;
    }else {
        HTMLdata = [NSString stringWithFormat:@"<body style='padding:0px;margin:0px;'>%@%@</body>", seedString, @"<br><img src='images/Default.png'>"];
    }   
    [homeView loadHTMLString:HTMLdata baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] resourcePath]]];
}

© Stack Overflow or respective owner

Related posts about iphone-sdk

Related posts about objective-c