I am trying to use `WKScriptMessageHandlerProtocol...
# ios
d
I am trying to use
WKScriptMessageHandlerProtocol
which has one abstract function defined, but when building the project it wants me to implement all of the members for NSObject? Does anyone know how to fix that?
r
Subclass from NSObject? I don't know it is possible to subclass
d
this is how it is defined in kotlin mp
Copy code
@kotlinx.cinterop.ExternalObjCClass public interface WKScriptMessageHandlerProtocol : platform.darwin.NSObjectProtocol {
    @kotlinx.cinterop.ObjCMethod public abstract fun userContentController(userContentController: platform.WebKit.WKUserContentController, didReceiveScriptMessage: platform.WebKit.WKScriptMessage): kotlin.Unit
}
message has been deleted
Looks like you can fix it by extending NSObject
Copy code
val scriptMessageHandler: platform.WebKit.WKScriptMessageHandlerProtocol = object : platform.WebKit.WKScriptMessageHandlerProtocol, NSObject() {
    override fun userContentController(
        userContentController: WKUserContentController,
        didReceiveScriptMessage: WKScriptMessage
    ) {
        println("Received the following message ${didReceiveScriptMessage.body}")
    }
}
n
yep, and you’d have to do the same in Swift IIRC
❤️ 1