You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

KMP使用WKWebView加载报错‘缺少权限’问题排查与解决

Kotlin Multiplatform iOS端WKWebView加载网页失败的解决方案

在KMM的iosMain模块中实现了如下Composable函数,用于通过WKWebView加载指定URL:

@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()
  )
}

运行后出现网页加载失败的问题,报错提示缺少com.apple.developer.web-browser-engine权限。尽管查阅资料确认该场景无需额外权限,且尝试将权限添加到iosApp.entitlements文件后仍未解决。

经过排查,可通过以下两种方式解决问题:

  • 避免将WKWebView嵌入LazyList组件内
  • 若加载的是HTTP协议的网页,需在Info.plist文件中配置App Transport Security Settings

内容的提问来源于stack exchange,提问作者Robert Jamison

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.17 12:42:34