0

I have created sample app for Cocoa Touch Framework and have passed WKWebView with sample url. I have used that framework in one of the app, and try to open wkwebview from main class. Below is my code of cocoa touch framework. Its always showing me Could not signal service com.apple.WebKit.Networking: 113: Could not find specified service this message in console.

import UIKit
import WebKit

public class ConnectedAppController: UIViewController, WKNavigationDelegate {

    var webView : WKWebView!

  override public func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.

    }

  public func opensampleWebView() {

    let myBlog = "https://www.google.com/"
    let url = NSURL(string: myBlog)
    let request = URLRequest(url: url! as URL)

    // init and load request in webview.
    webView = WKWebView(frame: self.view.frame)
    webView.navigationDelegate = self
    self.view.addSubview(webView)
    webView.load(request)
  }

  private func webView(webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error) {
    print(error.localizedDescription)
  }
  public func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
    print("Strat to load")
  }
  public func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
    print("finish to load")
  }
Kashif Jilani
  • 1,207
  • 3
  • 22
  • 49

2 Answers2

0

It's not obvious from your question, but I suspect you're calling opensampleWebView from a prepareForSegue call in another class.

Although you're correctly calling self.view.addSubview(webView) before webView.load(request), I suspect the view that you're attempting to add to hasn't been loaded yet.

If you call opensampleWebView() in viewDidLoad is there any difference?

override public func viewDidLoad() {
    super.viewDidLoad()
    opensampleWebView()
 }
James Webster
  • 31,873
  • 11
  • 70
  • 114
0

You need to override the function loadView()

Swift 4

public class ConnectedAppController: UIViewController, WKNavigationDelegate {

    var webView : WKWebView!

    override func loadView() {
        webView = WKWebView()
        webView.navigationDelegate = self
        view = webView
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        self.webView.allowsBackForwardNavigationGestures = true
        let myBlog = "https://www.google.com/"
        if let url = URL(string: myBlog) {
            self.webView.load(URLRequest(url: url))
        }

    }

}
Shan Ye
  • 2,622
  • 19
  • 21
  • It's still not working, I called this in Cocoa Touch Framework – Kashif Jilani Jan 19 '18 at 06:51
  • I just tried the code above, it works. try https://stackoverflow.com/questions/44585980/com-apple-webkit-webcontent-drops-113-error-could-not-find-specified-service – Shan Ye Jan 19 '18 at 09:58