4

ViewControllerUIWebView内にFBコメントプラグインを簡単にロードできます

@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];

コメントが読み込まれているのがわかりますが、高さがおかしいだけで、自動リサイズに失敗したようですか? モバイル サファリを使用している場合は、コメント全体を表示できます。

シミュレーターのスクリーンショット

4

4 に答える 4

4

このコードを使用して、iOS UIWebview に fb コメントを表示できます

  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 URL を使用してください

これはあなたを助けるかもしれません

于 2013-03-28T04:05:15.723 に答える
2

baseURL を指定する必要があります

[webView loadHTMLString:html baseURL:[NSURL URLWithString:@"http://www.example.com"]];
于 2013-03-26T07:10:05.803 に答える
0

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

于 2013-05-17T11:42:38.570 に答える