Failed to load full Facebook comment plugins inside iOS UIWebView

I have a simple ViewController to load FB comment plugins inside a UIWebView

 @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; UIWebView * webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320.0f, 1505.0f)]; NSString * html = @"\ <!DOCTYPE html>\ <html xmlns:fb='http://ogp.me/ns/fb#'>\ <head>\ <meta name='viewport' content='width=device-width, initial-scale=1.0'>\ </head>\ <body style='background-color:red;'>\ \ <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 = 'http://connect.facebook.net/en_US/all.js#xfbml=1&appId=xxx';\ fjs.parentNode.insertBefore(js, fjs);\ }(document, 'script', 'facebook-jssdk'));</script>\ \ <fb:comments href='http://example.com' num_posts='10'></fb:comments>\ \ </body>\ </html>\ "; [webView loadHTMLString:html baseURL:nil]; [self.view addSubview:webView]; 

I can see that the comments are loading, but only the height is weird, it seems automatic resizing failed? I can view all comments if I use mobile safaris.

Screenshot from Simulator

+4
source share
4 answers

you can use this code to display fb comment in iOS UIWebview

  UIWebView *fbWebview=[[UIWebView alloc]initWithFrame:CGRectMake(0, 0, 320, 1505)]; [fbWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://www.facebook.com/Levis"]]]; CGRect scrollViewFrame = CGRectMake(0, 0, 320, 1024); UIScrollView *scrollViewMain = [[UIScrollView alloc] initWithFrame:scrollViewFrame]; CGSize scrollViewContentSize = CGSizeMake(320, 1505); [scrollViewMain setContentSize:scrollViewContentSize]; [scrollViewMain setBounces:NO]; [scrollViewMain setScrollEnabled:YES]; [scrollViewMain setShowsVerticalScrollIndicator:YES]; [scrollViewMain setBackgroundColor:[UIColor redColor]]; [scrollViewMain addSubview:fbWebview]; [self.view addSubview:scrollViewMain]; 

instead of https://www.facebook.com/Levis "use your FB URL

it can help you

+4
source

You need to specify baseURL

 [webView loadHTMLString:html baseURL:[NSURL URLWithString:@"http://www.example.com"]]; 
+2
source

@Howard you can use http://www.facebook.com/plugins/comments.php?href=http://www.google.com 'scroll =' yes' profile = 'yes' frameborder =' 0 'style = 'border: none; overflow: hidden; width: 300px; height: 30px; "data-href = ' http://www.google.com ' allowTransparency = 'true'>"

0
source

Same problem. The solution was not to use a local HTML file (or HTML string). Upload the HTML file to the server and use:

 NSURL *url = [NSURL URLWithString:@"http://www.blablblab.com/yourfile.html"]; [self.webview loadRequest:[NSURLRequest requestWithURL:url]]; 

instead:

 [self.webview loadHTMLString:localString baseURL:nil]; 

I have not yet discovered why there is a difference in the layout when the file is on the server, but when it is a local file, the height of my view of Facebook comments was always reduced to "height: 160". Apparently, this is because of the "all.js" facebook script ( this question, respectively).

0
source

All Articles