ioswkwebviewkotlin-multiplatformentitlements

KMP Build using WKWebView is `missing entitlements`


I'm using Kotlin Multiplatform to generate a WebView in my iosMain implementation:

@Composable
actual fun LoadUrl(url: String) {
  val webView = remember { WKWebView() }
  UIKitView(
    factory = {
      webView.apply {
        WKWebViewConfiguration().apply {
          allowsInlineMediaPlayback = true
          allowsAirPlayForMediaPlayback = true
          allowsPictureInPictureMediaPlayback = true
        }
        loadRequest(NSURLRequest(NSURL(string = url)))
      }
      webView
    },
    modifier = Modifier.fillMaxSize()
  )
}

Unfortunately, it fails to load. My understanding is that no additional entitlements are required, but the error says otherwise:

2024-10-04 23:29:07.074826-0400 iosApp[7557:140326] [assertion] Error acquiring assertion: <Error Domain=RBSServiceErrorDomain Code=1 "((target is not running or doesn't have entitlement com.apple.developer.web-browser-engine.rendering AND target is not running or doesn't have entitlement com.apple.developer.web-browser-engine.networking AND target is not running or doesn't have entitlement com.apple.developer.web-browser-engine.webcontent))" UserInfo={NSLocalizedFailureReason=((target is not running or doesn't have entitlement com.apple.developer.web-browser-engine.rendering AND target is not running or doesn't have entitlement com.apple.developer.web-browser-engine.networking AND target is not running or doesn't have entitlement com.apple.developer.web-browser-engine.webcontent))}>

I have tried adding the entitlements to my iosApp.entitlements file, but that doesn't seem to solve the problem. All the research online tells me that I shouldn't even have to add entitlements to run this.

SOLVED:

  1. Do not embed a WebView in a LazyList
  2. [Only if you're using http instead of https] Put the App Transport Security Settings settings in your Info.plist file, not anywhere else.

Solution

  • try to add NSAppTransportSecurity into your Info.plist

    <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
    </dict>