DoctorWho
DoctorWho

Reputation: 1116

Open a webview using Compose multiplatform not working

I'm trying to open a page inside a webview using compose multiplatform. I'm able to do Android side but iOS side not working property. here the error from XCODE console:

Failed to resolve host network app id to config: bundleID: com.apple.WebKit.Networking instance ID: Optional([_EXExtensionInstanceIdentifier: 919784EC-C072-4E95-A52E-B811B0E0F898])

and here my webview inside iosApp:

@OptIn(ExperimentalForeignApi::class)
@Composable
actual fun PlatformWebView(
    url: String,
    onUrlChange: (String) -> Unit
) {
    UIKitView(
        factory = {
            val webView = WKWebView(frame = CGRectMake(0.0,0.0,0.0,0.0), configuration = WKWebViewConfiguration())
            webView.navigationDelegate = object : NSObject(), WKNavigationDelegateProtocol {
                override fun webView(
                    webView: WKWebView,
                    decidePolicyForNavigationResponse: WKNavigationResponse,
                    decisionHandler: (WKNavigationResponsePolicy) -> Unit
                ) {
                    val responseUrl = webView.URL?.absoluteString ?: ""
                    if (responseUrl.startsWith("https://www.google.it")) {
                        val token = extractTokenFromCookies(responseUrl)
                        if (token != null) {
                            onUrlChange("myapp://callback?token=$token")
                        }
                    } else {
                        onUrlChange(responseUrl)
                    }
                    decisionHandler(WKNavigationResponsePolicy.WKNavigationResponsePolicyAllow)
                }
            }
            webView.loadRequest(NSURLRequest(NSURL(string = url)))
            webView
        }
    )
}

can someone explain me why is not working? thanks in advance

Upvotes: 0

Views: 16

Answers (0)

Related Questions