【发布时间】:2018-05-05 13:16:16
【问题描述】:
只是无法找出这个webView 有什么问题,它只是保持空白没有错误。如果我尝试不使用视频 id 参数而只使用“https://www.apple.com”,它就可以工作。有什么想法吗?
import UIKit
import WebKit
class VideoPlayerVC: UIViewController, WKUIDelegate {
@IBOutlet weak var webview2: WKWebView!
var videoId: String?
override func viewDidLoad() {
//test video id, this prints the booty workouts id on youtube!This target also opens on youtube the id on the end of this url: https://www.youtube.com/watch?v=695PN9xaEhs
if let videoId = videoId {
print(videoId)
}
webview2.load(URLRequest(url: URL(fileURLWithPath: "https://www.youtube.com/watch?v=\(videoId)")))
}
}
【问题讨论】:
-
你的视频 ID 是什么
-
我认为,您没有获得视频 ID
-
是的,我打印了它,它给出了正确的值。检查代码中的评论视频ID是:695PN9xaEhs
-
@PatrikRikama-Hinnenberg 你必须!它将作为 Optional("695PN9xaEhs") 附加在视频 url 中,创建字符串 url 然后在将其传递到 URL 之前打印它
-
@Sh_Khan 是的,现在我看到它打印了可选的!唔。如何在再次使用之前保存解包的值?