Ali Ersöz
Ali Ersöz

Reputation: 16086

Facebook comments in UIWebView could not be loaded

I would like to add a facebook comment-box plug in to my app.

All I did is what the documents say. But I could not be able to load the comment box successfully.

I have a local html file in my app which looks like;

<html>
    <body>
        <div id="fb-root"></div>
        <script>(function(d, s, id) {
                 var js, fjs = d.getElementsByTagName(s)[0];
                 if (d.getElementById(id)) return;
                 js = d.createElement(s); js.id = id;
                 js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1&appId=xxx";
                 fjs.parentNode.insertBefore(js, fjs);
                 }(document, 'script', 'facebook-jssdk'));</script>

        <div class="fb-comments" data-href="http://www.google.com" data-num-posts="4" data-width="470"></div>
        <div>working?</div>
    </body>
</html>

Then, I am creating a UIWebView and trying to load this local html file which looks like below;

NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"comments" ofType:@"html"] isDirectory:NO];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[self.facebookCommentsWebView loadRequest:request];

But the webview just shows the dummy div that I have put. I can only see the "working?" text on the page. So it seems the html file is loading successfully but the comment box is not.

Have an idea on that?

By the way when I am trying to serve the html file in my computer and loading the webview with url: "http:/localhost:3000" I can see the comments.

[self.facebookCommentsWebView loadRequest:[[NSURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://localhost:3000"]] ];

But, I do not want to serve a page for that.

Thanks in advance.

Upvotes: 0

Views: 786

Answers (1)

Ali Ers&#246;z
Ali Ers&#246;z

Reputation: 16086

It seems you need to update this part:

js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1&appId=xxx";

to:

js.src = "http://connect.facebook.net/en_GB/all.js#xfbml=1&appId=xxx";

Upvotes: 2

Related Questions