0

I am new to swift and apple development in general (coming from JS world). I am trying to do a simple desktop app by wrapping WKWebView. Part where ViewController creates a webView works ok. At least it looks so: It loads a webpage :)

But when I click into any input field I am not able to write anything. There's even no cursor visible in the field.

Basically only clicking by mouse/touchpad works. But mouse cursor is not changing when hovering over elements (e.g. buttons and also the textfields). It looks to me there is some kind of mask/layer above the webpage. Clicking is propagated to page itself but not the hovers and key strokes

Is there any special project settings/rights enabling keyboard in the app? How can I make the page inputs editable?

More details:

  • Clicking the textfield works (it changes e.g. border color based on focus selector)
  • clicking <a> links in the webview works
  • right-mouse clicks seems to work (it shows copy/paste options etc)
  • pasting by right-mouse click into the field works

code:

import Cocoa
import SafariServices.SFSafariApplication
import WebKit

class ViewController: NSViewController, WKNavigationDelegate {

     @IBOutlet var ww: WKWebView!

     override func viewDidLoad() {
         super.viewDidLoad()

         ww.navigationDelegate = self
         ww.load(URLRequest(url: URL(string: "https://www.google.com")!))
         view = ww
    }
}

My storyboard: enter image description here

  • Ww is WebKit View
  • Ww covers all the View area (drag & dropped by mouse)

THANKS for any answer or hint!

Michal Roharik
  • 141
  • 1
  • 8

1 Answers1

0

Your original code works for me. You need to disable Sandbox Capabilities:

enter image description here

With this disabled I was able to both load and interact with the webview.

Community
  • 1
  • 1
Alex Bailey
  • 793
  • 9
  • 20
  • thanks for reply. Unfortunately it doesn't work for me :( what your story board looks like? – Michal Roharik Nov 28 '18 at 13:29
  • sorry I missed the NSViewController -> UIViewController swap. What is the difference please? Also my xcode reports: `Type 'ViewController' does not conform to protocol 'NSObjectProtocol'` when I try to change that – Michal Roharik Nov 28 '18 at 13:36
  • OK, I've find out that UIViewController is for ios applications. I've stated in my question that I am looking for desktop app solution, which is about NSViewController, I believe. Thanks anyway – Michal Roharik Nov 28 '18 at 13:56