Search code examples
iosswiftvimeo

Nothing displayed when trying to run a Vimeo video iOS App


I am trying to run a vimeo video in my app, and the method that makes the most sense to me is the method from this example [ https://stackoverflow.com/a/15918011/4856759 ].

So I have attempted to recreate this method in swift with my own vimeo link, but all I get is a blank screen.

As far as I can tell I have created the relevant string, converted it an NSString and loaded it using the loadHTMLString method - what am I missing?

@IBOutlet weak var webView: UIWebView!

override func viewDidLoad() {
    super.viewDidLoad()

    var embedHTML = "<iframe width=\"300\" height=\"250\" src=\"http://www.vimeo.com/113067409" frameborder=\"0\" allowfullscreen></iframe>"

    var html: NSString = NSString(string: embedHTML)

    webView.loadHTMLString(html, baseURL: nil)
}

Solution

  • Your link is valid, but the way you are embedding the HTML for vimeo is not correct and also you have to set the base url to "http://" instead of nil.

    Here is working code:-

        @IBOutlet weak var webView: UIWebView!
    
        override func viewDidLoad() {
            super.viewDidLoad()
            var embedHTML="<html><head><style type=\"text/css\">body {background-color: transparent;color: white;}</style></head><body style=\"margin:0\"><iframe src=\"//player.vimeo.com/video/113067409?autoplay=1&amp;loop=1\" width=\"1024\" height=\"768\" frameborder=\"0\" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>";
    
            webView.delegate = self
            var url: NSURL = NSURL(string: "http://")!
            webView.loadHTMLString(embedHTML as String, baseURL:url )
    }