无法在iOS UIWebView中加载完整的Facebook评论插件 [英] Unable to load full Facebook comment plugins inside an iOS UIWebView

查看:156
本文介绍了无法在iOS UIWebView中加载完整的Facebook评论插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的 ViewController 来加载UIWebView中的FB评论插件

I have a simple ViewController to load FB comments 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 the comments being loaded, but just the height is strange, seems auto resize failed? I can view the whole comments if I am using mobile safari.

推荐答案

您可以使用此代码在iOS UIWebview中显示fb注释

you can use this code for displaying the 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];

而不是 https://www.facebook.com/Levis 使用您的FB网址

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

这可能对您有所帮助

这篇关于无法在iOS UIWebView中加载完整的Facebook评论插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆