[Bug]: iOS 18.4.1 跳转到 Flutter 页面 直接卡死
请描述遇到的问题,以及您所期望的正确的结果
1、创建了一个 Flutter 项目:flutter create -t module flutter_module 2、注册路由
static Map<String, FlutterBoostRouteFactory> routerMap ={
'mainPage': (settings, uniqueId) {
return CupertinoPageRoute(
settings: settings,
builder: (_) {
Map<String, dynamic> parameters = settings.arguments as Map<String, dynamic>? ?? {};
return MainPage(
parameters: parameters,
);
});
},
}
3、启动 FlutterBoost
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
setupFlutterEngine(application: application)
return true
}
private func setupFlutterEngine(application: UIApplication) {
let delegate = FlutterBoostDelegate()
// 启动 FlutterBoost
FlutterBoost.instance().setup(application, delegate: delegate) { [weak self] engine in
self?.flutterEngine = engine
}
}
界面跳转
let options = FlutterBoostRouteOptions()
options.pageName = "mainPage"
FlutterBoost.instance().open(options)
4、直接卡死在 pushFlutterRoute 这个方法的 let vc: FBFlutterViewContainer = FBFlutterViewContainer() 这一行代码
func pushFlutterRoute(_ options: FlutterBoostRouteOptions!) {
let vc: FBFlutterViewContainer = FBFlutterViewContainer()
......
}
Flutter Version: Flutter 3.29.3 • channel stable • https://github.com/flutter/flutter.git Framework • revision ea121f8859 (4 weeks ago) • 2025-04-11 19:10:07 +0000 Engine • revision cf56914b32 Tools • Dart 3.7.2 • DevTools 2.42.3
flutter_boost Version: flutter_boost: git: url: 'https://github.com/alibaba/flutter_boost.git' ref: '4.6.1'
iOS Version: Xcode Version 16.3 (16E140) iOS 18.4.1 手机 iPhone 15 Pro
每次 跳转 Flutter 页面 项目都直接卡死,怎么才能在18.4.1正常跑起来?测试在18.2 是正常的。
请说明如何操作会遇到上述问题
No response
在下面填入关键复现代码
复现的平台
iOS
Flutter SDK版本
3.29.3
FlutterBoost版本
4.6.1
是否延迟初始化FlutterBoost
No
解决方案
你是国航手机遇到此问题么? 我是国外部分手机有此问题,国航手机未复现
你是国航手机遇到此问题么? 我是国外部分手机有此问题,国航手机未复现
使用的是国行的,不知道是不是跟这个关系,目前就是发现跟手机系统版本有问题,系统升级到18.4.1 就有这个问题,18.2 的时候都是正常的
大佬,有解决方案吗? 我这也是 到这儿就不往下走了 let vc: FBFlutterViewContainer = FBFlutterViewContainer()
let delegate = FlutterBoostDelegate()
// 启动 FlutterBoost
FlutterBoost.instance().setup(application, delegate: delegate) { [weak self] engine in
self?.flutterEngine = engine
}
代理做成单利试试 let delegate = BoostDelegate.shared
我用demo测试,也出现这个情况:
-
(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; }
当打印如下就正常显示: 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'}
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()
}