Triggered by Thread: 0
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libswiftCore.dylib 0x1932eba54 swift_getObjectType + 36
1 path_provider_foundation 0x105060cdc static PathProviderPlugin.register(with:) + 88
2 path_provider_foundation 0x105060de8 @objc static PathProviderPlugin.register(with:) + 56
3 Runner 0x104f33b54 +[GeneratedPluginRegistrant registerWithRegistry:] + 520 (GeneratedPluginRegistrant.m:66)
4 Runner 0x104f35ab8 AppDelegate.application(_:didFinishLaunchingWithOptions:) + 96 (AppDelegate.swift:10)
5 Runner 0x104f35da8 @objc AppDelegate.application(_:didFinishLaunchingWithOptions:) + 196
6 UIKitCore 0x1853cd430 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 312
7 UIKitCore 0x1853ce890 -[UIApplication _callInitializationDelegatesWithActions:forCanvas:payload:fromOriginatingProcess:] + 2788
8 UIKitCore 0x1853d33d0 -[UIApplication _runWithMainScene:transitionContext:completion:] + 856
9 UIKitCore 0x184a71ee4 -[_UISceneLifecycleMultiplexer completeApplicationLaunchWithFBSScene:transitionContext:] + 104
10 UIKitCore 0x184f94bd8 _UIScenePerformActionsWithLifecycleActionMask + 96
11 UIKitCore 0x184a727e4 __101-[_UISceneLifecycleMultiplexer _evalTransitionToSettings:fromSettings:forceExit:withTransitionStore:]_block_invoke + 188
12 UIKitCore 0x184a72358 -[_UISceneLifecycleMultiplexer _performBlock:withApplicationOfDeactivationReasons:fromReasons:] + 212
13 UIKitCore 0x184a7263c -[_UISceneLifecycleMultiplexer _evalTransitionToSettings:fromSettings:forceExit:withTransitionStore:] + 576
14 UIKitCore 0x184a72040 -[_UISceneLifecycleMultiplexer uiScene:transitionedFromState:withTransitionContext:] + 244
15 UIKitCore 0x184a7c354 __186-[_UIWindowSceneFBSSceneTransitionContextDrivenLifecycleSettingsDiffAction _performActionsForUIScene:withUpdatedFBSScene:settingsDiff:fromSettings:transitionContext:lifecycleActionType:]_block_invoke + 140
核心问题是 需要先创建 FlutterEngine, 再执行GeneratedPluginRegistrant registerWithRegistry
flutter create 创建的iOS 项目,默认是sb 初始化了 FlutterViewController
在Appdelegete 调用 GeneratedPluginRegistrant registerWithRegistry, 没有任何问题,
如果程序员自己控制,需要注意调用的次序。
不讲太多,上代码:
集成FlutterBoost为例
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
printLog("Native: didFinishLaunchingWithOptions")
//FlutterPluginRegistry flutterboost 已经实现了,不需要再实现
//GeneratedPluginRegistrant.register(with: <#T##any FlutterPluginRegistry#>)
self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.backgroundColor = UIColor.white
let boostSetupOptions = FlutterBoostSetupOptions.createDefault()
FlutterBoost.instance().setup(application, delegate: SMFlutterBoostDelegate.shared, callback: { [weak self] boostEngine in
guard let self = self else { return }
printLog("Native: FlutterBoost boostEngine install result: \(boostEngine != nil ? "success ✅": "error ❎")")
guard let boostEngine = boostEngine else { return }
printLog("Native: flutterEngine.run() ")
let flutterViewController = SMFlutterVC(engine: boostEngine, nibName: nil, bundle: nil)
let navigationController = UINavigationController(rootViewController: flutterViewController)
self.window?.rootViewController = navigationController
self.window?.makeKeyAndVisible()
}, options: boostSetupOptions)
return true
}