0
顯示YouTube視頻,我試圖用一個WKWebView的iOS 9頁的一個恰好有一個iframe一個YouTube視頻下方。視頻不顯示。相同的視頻在Safari中工作,因此似乎不是iOS問題,我假設我缺少視圖中的配置選項。示例網址是http://www.w3schools.com/html/tryit.asp?filename=tryhtml_youtubeiframe。wkwebview不會在iframe
import UIKit
import WebKit
class ViewController: UIViewController, WKNavigationDelegate
{
var webView : WKWebView!
override func viewDidLoad()
{
super.viewDidLoad()
let webviewConfiguration = WKWebViewConfiguration()
webviewConfiguration.allowsInlineMediaPlayback = true
webviewConfiguration.preferences.javaScriptCanOpenWindowsAutomatically = true
webviewConfiguration.allowsAirPlayForMediaPlayback = true
webviewConfiguration.allowsPictureInPictureMediaPlayback = true
webviewConfiguration.requiresUserActionForMediaPlayback = false
webView = WKWebView(frame: self.view.bounds,
configuration: webviewConfiguration)
webView.navigationDelegate = self
self.view = webView
let url = NSURL(string: "http://www.w3schools.com/html/tryit.asp?filename=tryhtml_youtubeiframe")
let req = NSURLRequest(URL: url!)
self.webView!.loadRequest(req)
}
override func didReceiveMemoryWarning()
{
super.didReceiveMemoryWarning()
}
func webView(webView: WKWebView,
didFailNavigation navigation: WKNavigation!,
withError error: NSError)
{
print("didFailNavigation \(error)")
}
func webView(webView: WKWebView,
didFailProvisionalNavigation navigation: WKNavigation!,
withError error: NSError)
{
print("didFailProvisionalNavigation \(error)")
}
}
@TofuBeer嘗試...... –
D'哦!謝謝。我爲服務器添加了異常,但並不知道,當然,youtube也是http,需要一個例外......過了漫長的一天:-)如果蘋果在這種情況下吐出一個錯誤,那就好了! – TofuBeer