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

iOS原生调用Flutter模块时flutter_inappwebview注册异常求助

解决iOS原生调用Flutter模块时flutter_inappwebview的未注册视图异常

问题场景

直接运行Flutter独立应用时,flutter_inappwebview功能正常;但通过iOS原生应用调用Flutter模块时,触发以下异常:

未处理异常:PlatformException(unregistered_view_type, 一个UIKitView组件尝试创建一个未注册类型的PlatformView: < com.pichillilorenzo/flutter_inappwebview >,如果你是该PlatformView的开发者,请确保调用了registerViewFactory。
如果你不是该PlatformView的开发者,请确保调用了GeneratedPluginRegistrant.register。, null)
#0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:652:7)
#1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:310:18)
<异步挂起>
#2 PlatformViewsService.initUiKitView (package:flutter/src/services/platform_views.dart:242:5)
<异步挂起>
#3 _UiKitViewState._createNewUiKitView (package:flutter/src/widgets/platform_view.dart:662:44)
<异步挂起>

解决方案

1. 确保原生工程正确注册Flutter插件

在iOS原生代码初始化Flutter引擎的位置,必须调用GeneratedPluginRegistrant注册所有Flutter插件,包括flutter_inappwebview。示例Swift代码:

import Flutter
import flutter_inappwebview

// 初始化Flutter引擎
let flutterEngine = FlutterEngine(name: "MyFlutterEngine")
flutterEngine.run()

// 注册所有插件
GeneratedPluginRegistrant.register(with: flutterEngine)

如果使用FlutterViewController,需确保它关联已注册插件的引擎,而非默认空引擎:

let flutterViewController = FlutterViewController(engine: flutterEngine, nibName: nil, bundle: nil)
present(flutterViewController, animated: true)

2. 手动注册flutter_inappwebview插件(自动注册失效时)

若GeneratedPluginRegistrant未自动注册该插件,可手动执行注册:

// 引擎初始化完成后调用
FLTInAppWebViewPlugin.register(with: flutterEngine.registrar(forPlugin: "com.pichillilorenzo/flutter_inappwebview"))

3. 检查依赖兼容性与安装状态

  • 确认pubspec.yaml中flutter_inappwebview版本与当前Flutter SDK兼容,建议升级至最新稳定版
  • 执行flutter pub get确保Flutter模块依赖安装完成
  • 进入iOS原生工程目录,执行pod install确保原生侧依赖正确集成

4. 排查注册流程干扰

检查原生工程中是否存在自定义插件注册逻辑,避免覆盖或干扰flutter_inappwebview的视图工厂注册流程

内容的提问来源于stack exchange,提问作者Rajkumar M

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.07 01:11:30