简体   繁体   English

UIWebView同时显示本地图像和Facebook评论

[英]UIWebView to display both local image and facebook comment

I'm facing an issue on an UIWebView. 我在UIWebView上遇到问题。 I got a WebView which display an html string. 我有一个显示HTML字符串的WebView。 This html string contains : 该html字符串包含:

  • Html text HTML文字
  • Local images 本地图片
  • fb:comments fb:评论

At first i only had Html + local Image so I was using th well known method : 起初我只有Html + Local Image,所以我使用的是众所周知的方法:

NSString *path = [[NSBundle mainBundle] bundlePath];
NSURL *baseURL = [NSURL fileURLWithPath:path];
[webview loadHTMLString:htmlString baseURL:baseURL];

Everything worked perfectly. 一切正常。 But then i had to implement facebook comments http://developers.facebook.com/docs/reference/plugins/comments/ 但后来我不得不实施Facebook评论http://developers.facebook.com/docs/reference/plugins/comments/

Since my old BaseURL wasn't working anymore for facebook i tried to load with 由于我的旧BaseURL对于Facebook不再可用,因此我尝试加载

NSURL *baseURL = [NSURL URLWithString:@"http://www.facebook.com/"];

This made my facebook work but the local image aren't displayed within the webview, even with absolute path. 这使我的facebook正常工作,但是即使具有绝对路径,本地图像也不会显示在webview中。

Any help would be appreciate. 任何帮助将不胜感激。 Thanks for your time 谢谢你的时间

There's a solution to use the img tag with base64 encoded image data instead of the url. 有一种解决方案,可以将img标签与base64编码的图像数据一起使用,而不是使用url。 That should not be a problem as you have the image locally, see the html sample . 这应该不成问题,因为您在本地拥有图片,请参见html 示例

To test it quickly you can use the online encoding service (50kb limitation) 要快速测试,您可以使用在线编码服务 (限制为50kb)

The original answer is here 原始答案在这里


And the truncated base64-sample for future reference: 以及截短的base64-sample以供将来参考:

<html>
<body>
<div id="fb-root"></div>
FB1
    <script>
        window.fbAsyncInit = function() {
            FB.init({
                    appId      : null,
                    channelUrl : null,
                    status     : true,
                    cookie     : true,
                    xfbml      : true 
                    });

        };

        (function(d){
         var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
         if (d.getElementById(id)) {return;}
         js = d.createElement('script'); js.id = id; js.async = true;
         js.src = "//connect.facebook.net/en_US/all.js";
         ref.parentNode.insertBefore(js, ref);
         }(document));
        </script>

    FB2
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUh......lAmeQ/IAAAAASUVORK5CYII=" alt="Screen Shot 2012-05-23 at 6.53.28 AM.png" />

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

</body>
</html>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM