加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Swift 4 WebKit webView不会加载带有附加参数的URL

发布时间:2020-12-14 04:47:08 所属栏目:百科 来源:网络整理
导读:只是无法找出这个webView有什么问题,它只是保持空白没有错误.如果我尝试没有视频ID参数,只是“ https://www.apple.com”它的工作原理.有任何想法吗? import UIKitimport WebKitclass VideoPlayerVC: UIViewController,WKUIDelegate { @IBOutlet weak var we
只是无法找出这个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)")))
    }
}

解决方法

你的身份证工作正常:

override func viewDidLoad() {
    super.viewDidLoad()
    let webView = WKWebView(frame: CGRect(x: 0,y: 0,width: self.view.frame.size.width,height: self.view.frame.size.height))
    self.view.addSubview(webView)
    let url = URL(string: "https://www.youtube.com/watch?v=695PN9xaEhs")
    webView.load(URLRequest(url: url!))
}

enter image description here

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读