Xcode GeneratedPluginRegistrant registerWithRegistry: crash解決辦法

image.png

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

核心問題是 需要先創(chuàng)建 FlutterEngine, 再執(zhí)行GeneratedPluginRegistrant registerWithRegistry

flutter create 創(chuàng)建的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
    }
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容