https://kotlinlang.org logo
#ios
Title
# ios
d

dazza5000

08/31/2020, 3:00 PM
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

Romain Dubreucq

08/31/2020, 3:06 PM
Subclass from NSObject? I don't know it is possible to subclass
d

dazza5000

08/31/2020, 3:08 PM
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

Nikolay Kasyanov

09/01/2020, 8:02 AM
yep, and you’d have to do the same in Swift IIRC
❤️ 1
17 Views