Trying to load Facebook-Comments plugin into UIWebView

I am trying to view the facebook comment plugin in UIWebView on an iPhone application.

I started with a Facebook tutorial for iOS that implemented single sign-on. The application delegate takes care of SSO on Facebook and then redirects me to my single view controller, which displays the title bar and UIWebView.

I am uploading a webview with a local file called "comments.html" that has been added and copied to my bundle / project folder.

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

My html file is a version of the plugin implementation created on the Facebook Comments plugin description site . I connected the URL and clicked "Get Code". I took the HTML5 code that was provided to me and stuck it in the HTML file

<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";
      fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));</script>

    <div class="fb-comments" data-href="http://www.bombslo.com" data-num-posts="4" data-width="470"></div>

</body>
</html>

UIWebView loads beautifully on my simulator. I hosted and ran the HTML on my device and it loads fine in Safari. The problem is that UIWebView will not load the Facebook comment plugin in the embedded UIWebView.

It is important to note that I am not getting a blank screen. I see two animated download bars typical of Facebook. Also note that the generated Facebook code comes in both HTML5 and XFBML. I tried to use both.

+6
source share
4

. Facebook iOS sdk AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
facebook = [[Facebook alloc] initWithAppId:@"your app id" andDelegate:self];
....
}

.

!

+2

, , http:// js.src

FB script .

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

Calling a feed dialogue unexpectedly helped! I called

[facebook dialog:@"feed" andDelegate:self];

and when you close the comment plugin is loaded correctly.

0
source

I tried all these solutions, but not one of these works. What works for me is setting the base URL UIWebView . According to the example question, let's say that I read the data into a variable, the htmlStrloading strategy will look like this

webview.loadHTMLString(htmlStr, baseURL: URL(string: "http://www.bombslo.com")!)

This works for me.

0
source

All Articles