[Bug]: iOS 17.7.2(iphone12)跳转 创建FBFlutterViewContainer时候卡死
请描述遇到的问题,以及您所期望的正确的结果
(同一个设备,多次调试,存在显示正常和显示失败卡死的情况),其他一些设备是可以正常使用。 使用官方提供的demo,delegate代码如下:
-
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame: [UIScreen mainScreen].bounds]; [self.window makeKeyAndVisible];
FlutterBoostSetupOptions* options = [FlutterBoostSetupOptions createDefault]; options.dartEntryPointArgs = @[ @"I'm from IOS!", @"--for-test" ];
MyFlutterBoostDelegate* delegate=[[MyFlutterBoostDelegate alloc ] init]; [[FlutterBoost instance] setup:application delegate:delegate callback:^(FlutterEngine engine) { NSObject<FlutterPluginRegistrar> registrar = [engine registrarForPlugin:@"plugin-name"]; FLNativeViewFactory* factory = [[FLNativeViewFactory alloc] initWithMessenger:registrar.messenger]; [[engine registrarForPlugin:@"
"] registerViewFactory:factory withId:@" "]; } options:options]; UIViewControllerDemo *vc = [[UIViewControllerDemo alloc] initWithNibName:@"UIViewControllerDemo" bundle:[NSBundle mainBundle]]; vc.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"hybrid" image:nil tag:0];
FBFlutterViewContainer *fvc = [[FBFlutterViewContainer alloc] init] ;
[fvc setName:@"tab_friend" uniqueId:nil params:@{} opaque:YES]; fvc.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"flutter_tab" image:nil tag:1];
UITabBarController *tabVC = [[UITabBarController alloc] init]; tabVC.viewControllers = @[vc,fvc];
UINavigationController *rvc = [[UINavigationController alloc] initWithRootViewController:tabVC];
delegate.navigationController=rvc;
self.window.rootViewController = rvc;
UIButton *nativeButton = [UIButton buttonWithType:UIButtonTypeCustom]; nativeButton.frame = CGRectMake(self.window.frame.size.width * 0.5 - 50, 200, 100, 40); nativeButton.backgroundColor = [UIColor redColor]; [nativeButton setTitle:@"push native" forState:UIControlStateNormal]; [nativeButton addTarget:self action:@selector(pushNative) forControlEvents:UIControlEventTouchUpInside]; [self.window addSubview:nativeButton];
UIButton *pushEmbeded = [UIButton buttonWithType:UIButtonTypeCustom]; pushEmbeded.frame = CGRectMake(self.window.frame.size.width * 0.5 - 70, 150, 140, 40); pushEmbeded.backgroundColor = [UIColor redColor]; [pushEmbeded setTitle:@"push embedded" forState:UIControlStateNormal]; [pushEmbeded addTarget:self action:@selector(pushEmbeded) forControlEvents:UIControlEventTouchUpInside]; [self.window addSubview:pushEmbeded];
return YES; }
当打印如下,即正常显示:
Failed to instantiate the default view controller for UIMainStoryboardFile 'Main' - perhaps the designated entry point is not set? flutter: The Dart VM service is listening on http://127.0.0.1:64296/10u-9h5XPkE=/ flutter: FlutterBoost_dart#page_visibility, #addGlobalObserver, Instance of 'AppGlobalPageVisibilityObserver' flutter: FlutterBoost_dart#boost_flutter_binding: handleAppLifecycleStateChanged AppLifecycleState.resumed flutter: dartEntrypointArgs: [I'm from IOS!, --for-test] flutter: FlutterBoost_dart#restoreStackForHotRestart, null, null flutter: FlutterBoost_dart#saveStackForHotRestart, [1748248963846/], {1748248963846/: Instance of 'FlutterContainer'}
当打印如下,加载失败,界面卡死: Failed to instantiate the default view controller for UIMainStoryboardFile 'Main' - perhaps the designated entry point is not set? flutter: The Dart VM service is listening on http://127.0.0.1:64296/10u-9h5XPkE=/ flutter: FlutterBoost_dart#page_visibility, #addGlobalObserver, Instance of 'AppGlobalPageVisibilityObserver' flutter: FlutterBoost_dart#boost_flutter_binding: handleAppLifecycleStateChanged AppLifecycleState.resumed flutter: dartEntrypointArgs: [I'm from IOS!, --for-test]
跳转代码:
self.flutterContainer = [[FBFlutterViewContainer alloc] init];
[self.flutterContainer setName:@"dbs_BatteryInfo" uniqueId:nil params:@{@"electricValue":electricValue,@"LanguageStr":LanguageStr} opaque:YES];
self.view.backgroundColor = [UIColor blackColor];
self.flutterContainer.view.backgroundColor = [UIColor blackColor];
self.flutterContainer.view.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
[self.view addSubview:self.flutterContainer.view];
[self addChildViewController:self.flutterContainer];
请说明如何操作会遇到上述问题
No response
在下面填入关键复现代码
复现的平台
Both
Flutter SDK版本
Dart 3.6.1
FlutterBoost版本
4.3.0
是否延迟初始化FlutterBoost
No
解决方案
在delegate初始化 :FBFlutterViewContainer *fvc = [[FBFlutterViewContainer alloc] init]; 神奇解决
你好,你说的 FlutterBoost版本 4.3.0
是在yaml文件中这么配置的 flutter_boost: git: url: 'https://github.com/alibaba/flutter_boost.git' ref: '4.3.0' 的吗? 我看到没有这个版本呢?
你好,你说的 FlutterBoost版本 4.3.0
是在yaml文件中这么配置的 flutter_boost: git: url: 'https://github.com/alibaba/flutter_boost.git' ref: '4.3.0' 的吗? 我看到没有这个版本呢?
4.6.5 也是一样的(4.3.0,是2023年用的)
你好,你说的 FlutterBoost版本 4.3.0 是在yaml文件中这么配置的 flutter_boost: git: url: 'https://github.com/alibaba/flutter_boost.git' ref: '4.3.0' 的吗? 我看到没有这个版本呢?
4.6.5 也是一样的(4.3.0,是2023年用的)
我现在用的是4.6.5的版本。根据你提供的思路,还是没有解决卡死的问题。
我在4.6.5上也是一样的问题,初始化FBFlutterViewContainer卡死
用官方的demo调试看看
我在4.6.5上也是一样的问题,初始化FBFlutterViewContainer卡死
是的,试试delegate初始化看看有没有效果
我在4.6.5上也是同样的问题,初始化FBFlutterViewContainer卡死
是的,尝试委托初始化看看有没有效果
好的
解决方案在这里 https://github.com/alibaba/flutter_boost/issues/2201#issuecomment-2957935156
FlutterBoost.m 中的预热引擎方法如下:
/// 提前预热引擎
- (void)warmUpEngine {
FlutterViewController* vc = [[FlutterViewController alloc] initWithEngine:self.engine
nibName:nil bundle:nil];
//卡死页面的代码地方
//下面这几行代码的调用时机应在在addChildVC后,没有addChildVC直接调用会有问题
[vc beginAppearanceTransition:YES animated:NO];
[vc endAppearanceTransition];
[vc beginAppearanceTransition:NO animated:NO];
[vc endAppearanceTransition];
}
解决方法:
- 初始化时关闭预热
AppDelegate.swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let ops:FlutterBoostSetupOptions = FlutterBoostSetupOptions()
//关闭预热
ops.warmUpEngine = false
let delegate = MyBoostAppDelegate.shared
FlutterBoost.instance().setup(application, delegate: delegate, callback: { engine in
}, options: ops)
return true
}
- 手动预热,最好在window的根控制器中,或其他控制器中,自己根据情况选择
ViewController.swift
override func viewDidLoad() {
super.viewDidLoad()
//手动预热
if let eg = FlutterBoost.instance().engine() {
let vc = FBFlutterViewContainer(engine: eg, nibName: nil, bundle: nil)
//隐藏视图
vc.view.isHidden = true
self.addChild(vc)
vc.beginAppearanceTransition(true, animated: false)
vc.endAppearanceTransition()
vc.beginAppearanceTransition(false, animated: false)
vc.endAppearanceTransition()
}