Facebook has this new feature that allows users to embed public posts on a web page. I want to try using this in an iPhone app inside a UIWebView. Escaping the required code is very simple, but even if I exit the code manually, the web view will not load the message properly. JavaScript doesn't work at all.
class WebViewController: UIViewController{ @IBOutlet weak var webView: UIWebView! override func viewDidLoad() { loadFacebookPost() } func loadFacebookPost(){ //Code from Facebook as a string var myHTML: String = "<html><body><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 = \"//connect.facebook.net/sv_SE/sdk.js#xfbml=1&version=v2.3\"; fjs.parentNode.insertBefore(js, fjs);}(document, 'script', 'facebook-jssdk'));</script><div class=\"fb-post\" data-href=\"https://www.facebook.com/BestofVines/posts/691077077726242\" data-width=\"350\"><div class=\"fb-xfbml-parse-ignore\"><blockquote cite=\"https://www.facebook.com/BestofVines/posts/691077077726242\"><p>Steven Tyler made this girl's day!</p>Posted by <a href=\"https://www.facebook.com/BestofVines\">Best Vines</a> on <a href=\"https://www.facebook.com/BestofVines/posts/691077077726242\">den 2 oktober 2015</a></blockquote></div></div></body></html>" webView.loadHTMLString(myHTML, baseURL: nil) }
This is the post I tried to insert.

And this is how it was displayed

I replaced all quotation marks with \" inside myHTML . What am I missing?
EDIT
I also tried this solution. This time the view is empty, showing nothing. Code:
import Foundation import UIKit import WebKit class WebViewController: UIViewController{ @IBOutlet var uiview: UIView! var webView: WKWebView? override func loadView() { super.loadView() self.webView = WKWebView() self.uiview = self.webView! } override func viewDidLoad() { super.viewDidLoad() loadFacebookPost() } func loadFacebookPost(){ var path = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as! NSString path = path.stringByAppendingString("/myHTML.html") var textHTML: String = "<html><body><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 = \"//connect.facebook.net/sv_SE/sdk.js#xfbml=1&version=v2.3\"; fjs.parentNode.insertBefore(js, fjs);}(document, 'script', 'facebook-jssdk'));</script><div class=\"fb-post\" data-href=\"https://www.facebook.com/BestofVines/posts/691077077726242\" data-width=\"350\"><div class=\"fb-xfbml-parse-ignore\"><blockquote cite=\"https://www.facebook.com/BestofVines/posts/691077077726242\"><p>Steven Tyler made this girl's day!</p>Posted by <a href=\"https://www.facebook.com/BestofVines\">Best Vines</a> on <a href=\"https://www.facebook.com/BestofVines/posts/691077077726242\">den 2 oktober 2015</a></blockquote></div></div></body></html>" var ok: Bool = textHTML.writeToFile(path as String, atomically: true, encoding: NSUTF8StringEncoding, error: NSErrorPointer()) if ok { println("Write done!") var url: NSURL = NSURL.fileURLWithPath(path as String, isDirectory: false)! webView!.loadRequest(NSURLRequest(URL: url)) } else { println("Error!") } } }
source share