Mysterious error when using a WKWebView in an InputMethodKit app

I modified an InputMethodKit example (fairly recent one from github, compiled fine and worked as expected on my machine as it was) to create a window with a WKWebView and the window doesn't load. I know that loadView is getting called, but the window never appears after calling showWindow on the window controller and there is a mysterious error in the console:

bootstrap_check_in():  (os/kern) unknown error code (44c)

From googling this it seems App Sandbox related, but I think I have everything set up correctly (App Sandbox on with outgoing connections allowed) Totally stumped, any help or ideas would be appreciated

Here's the relevant code:

View controller

import Foundation
import WebKit
import AppKit
class InputWindowViewController: NSViewController, WKUIDelegate {
    var webView: WKWebView!
    
    override func loadView() {
        NSLog("LoadView")
        webView = WKWebView()
        self.view = webView
        webView.uiDelegate = self
        webView.needsDisplay = true

    }
    override func viewDidLoad() {
        super.viewDidLoad()
        
        webView.load(URLRequest(url: URL(string:"https://www.apple.com")!))
    }
}

Window controller

import AppKit
import Foundation
import WebKit
class InputWindowController: NSWindowController {
    var controller: InputWindowViewController?
    override init(window: NSWindow?) {
        controller = nil
        super.init(window: window)
    }
    override func loadWindow() {
        self.window = NSWindow(contentViewController: controller!)
    }
    
    required init?(coder: NSCoder) {
        controller = nil
        super.init(coder: coder)
    }
}

AppDelegate

import Cocoa
import InputMethodKit
import WebKit
// Necessary to launch this app
class NSManualApplication: NSApplication {
    private let appDelegate = AppDelegate()

    override init() {
        super.init()
        self.delegate = appDelegate
    }
    
    required init?(coder: NSCoder) {
        // No need for implementation
        fatalError("init(coder:) has not been implemented")
    }
}




@main
class AppDelegate: NSResponder, NSApplicationDelegate {
    
    var server = IMKServer()
    var candidates = IMKCandidates()
    var inputWindowController = InputWindowController()

    func applicationDidFinishLaunching(_ notification: Notification) {
        
        // Insert code here to initialize your application
        server = IMKServer(name: Bundle.main.infoDictionary?["InputMethodConnectionName"] as? String, bundleIdentifier: Bundle.main.bundleIdentifier)
        
        inputWindowController = InputWindowController()
        inputWindowController.controller = InputWindowViewController()
        
        inputWindowController.loadWindow()
        inputWindowController.showWindow(self)
        
        candidates = IMKCandidates(server: server, panelType: kIMKSingleRowSteppingCandidatePanel, styleType: kIMKMain)
        
        NSLog("tried connection")
        
    }

    func applicationWillTerminate(_ notification: Notification) {
        // Insert code here to tear down your application
    }
}

This code is probably awful in a lot of other ways I don't realize, but I wanted to get a webview window up before I put a bunch of time into this thing

XCode 13.4 MacoOS 12.7.4

Replies

Oops, the webView.needsDisplay = true shouldn't be there. Symptoms are the same with and without.