UIWebView to display both local image and facebook comment

I am having a problem with UIWebView. I got a WebView that displays an html string. This html line contains:

  • HTML text
  • Local images
  • fb: comments

At first I only had Html + local Image, so I used the famous method:

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/

Since my old BaseURL no longer worked for facebook, I tried downloading using

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

This did my facebook job, but the local image does not appear in the webview even with an absolute path.

Any help would be appreciated. thank you for your time

+4
source share
1 answer

There is a solution to use the img tag with base64 encoded image data instead of the url. This should not be a problem since you have the image locally, see the html sample.

To quickly test it, you can use the online encoding service (50kb limit)

Original answer here


And a 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> 
+2
source

Source: https://habr.com/ru/post/1412631/


All Articles