Swift4 - WkwebView warning of Could not signal service com.apple.WebKit

13,638

I have tried to encode parameter and Its working fine for me. Please check below code.

var wkWebView = WKWebView()

override func viewDidLoad()
{
    super.viewDidLoad()

    self.automaticallyAdjustsScrollViewInsets = false
    self.wkWebView.translatesAutoresizingMaskIntoConstraints = false
    self.wkWebView.frame =  CGRect.init(x: 0, y: 0, width: self.wkWebView.frame.size.width, height: self.wkWebView.frame.size.height)
    self.view.addSubview(wkWebView)

    loadUrl()
}
override func viewWillLayoutSubviews()
{
    super.viewWillLayoutSubviews()
    self.wkWebView.frame =  CGRect.init(x: 0, y: 0, width: self.view.frame.size.width, height: self.view.frame.size.height)
    self.wkWebView.contentMode = .scaleAspectFit
}
func loadUrl()
{
    let webConfiguration = WKWebViewConfiguration()
    webConfiguration.allowsInlineMediaPlayback = true

    let url_join = "v=1p38GWfCIhQ"

    let myURL = URL(string: "https://www.youtube.com/watch?")
    var myRequest = URLRequest(url: myURL!)
    myRequest.httpMethod = "POST"
    myRequest.httpBody = url_join.data(using: String.Encoding.utf8)
    wkWebView.load(myRequest)
}

I hope It will also work for you. :)

Share:
13,638

Related videos on Youtube

tolerate_Me_Thx
Author by

tolerate_Me_Thx

Updated on June 04, 2022

Comments

  • tolerate_Me_Thx
    tolerate_Me_Thx almost 2 years

    I have a log when I load youtube URL in WKWebView.
    I have searched the same title of my question in stackOverFlow.
    But it didn't work for me.
    What's wrong with my code?
    And I use swift4 & xcode9.2.
    Thanks.

    Transport also set true.
    open

    Warning like this:

    Could not signal service com.apple.WebKit.Networking: 113: Could not find specified service

    import UIKit
    import WebKit
    
    class DetailViewController: UIViewController {
    
    var videoId: String = ""
    var videoTitle: String = ""
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
    
        loadUI()
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    func loadUI() {
    
        view.backgroundColor = UIColor.white
    
        naviSetting()
        webViewSetting()
    }
    
    func naviSetting() {
    
        self.title = videoTitle
    }
    
    func webViewSetting() {
    
        let webview = WKWebView(frame: CGRect(x: 0, y: 0, width: self.view.frame.width, height: self.view.frame.height))
    
        let url = URL(string: "https://www.youtube.com/watch?v=\(self.videoId)")
        let request = URLRequest(url: url!)
        webview.load(request)
        self.view.addSubview(webview)
    }
    }
    
    • Vinaykrishnan
      Vinaykrishnan about 6 years
    • tolerate_Me_Thx
      tolerate_Me_Thx about 6 years
      Yes, And it seems not work for me.
    • iOS Developer
      iOS Developer about 6 years
      @tolerate_Me_Thx Please check my Answer.
    • iOS Developer
      iOS Developer about 6 years
      @tolerate_Me_Thx Please accept my answer if you have fixed your error. Thanks in Advance.