UIWebView显示本地图像和Facebook评论 [英] UIWebView to display both local image and facebook comment
问题描述
我在UIWebView上遇到问题。
我有一个显示html字符串的WebView。此html字符串包含:
I'm facing an issue on an UIWebView. I got a WebView which display an html string. This html string contains :
- Html文本
- 本地图像
- fb:comments
起初我只有Html +本地图像所以我使用了众所周知的方法:
At first i only had Html + local Image so I was using th well known method :
NSString *path = [[NSBundle mainBundle] bundlePath];
NSURL *baseURL = [NSURL fileURLWithPath:path];
[webview loadHTMLString:htmlString baseURL:baseURL];
一切都很完美。
但是我必须实施Facebook评论 http://developers.facebook。 com / docs / reference / plugins / comments /
由于我的旧BaseURL不再用于facebook,我试图加载
Since my old BaseURL wasn't working anymore for facebook i tried to load with
NSURL *baseURL = [NSURL URLWithString:@"http://www.facebook.com/"];
这使得我的Facebook工作但是本地图像不会显示在webview中,即使是绝对路径。
This made my facebook work but the local image aren't displayed within the webview, even with absolute path.
任何帮助都会受到赞赏。感谢您的时间
Any help would be appreciate. Thanks for your time
推荐答案
有一个解决方案可以使用 img
标签使用base64编码的图像数据而不是url。
这应该不是问题,因为你在本地有图像,请参阅html 示例。
There's a solution to use the img
tag with base64 encoded image data instead of the url.
That should not be a problem as you have the image locally, see the html sample.
要快速测试,您可以使用在线编码服务(50kb限制)
To test it quickly you can use the online encoding service (50kb limitation)
原始答案是这里
截断的base64样本供将来参考:
And the truncated base64-sample for future reference:
<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>
这篇关于UIWebView显示本地图像和Facebook评论的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!