官方集成文档:https://github.com/alibaba/flutter_boost/blob/master/README_CN.md
一、 iOS篇
现将官方集成文档做一下精简:
注意:需要将libc++ 加入 "Linked Frameworks and Libraries" 中。
AppDelegate.h文件的对应修改:使用FLBFlutterAppDelegate作为AppDelegate的超类
如下:
@interface AppDelegate : FLBFlutterAppDelegate <UIApplicationDelegate>
@end
创建工具类DemoRouter:为应用程序实现FLBPlatform协议方法。
代码如下:
@interface DemoRouter : NSObject<FLBPlatform>
@property (nonatomic,strong) UINavigationController *navigationController;
+ (DemoRouter *)sharedRouter;
@end
@implementation DemoRouter
- (void)openPage:(NSString *)name
params:(NSDictionary *)params
animated:(BOOL)animated
completion:(void (^)(BOOL))completion
{
if([params[@"present"] boolValue]){
FLBFlutterViewContainer *vc = FLBFlutterViewContainer.new;
[vc setName:name params:params];
[self.navigationController presentViewController:vc animated:animated completion:^{}];
}else{
FLBFlutterViewContainer *vc = FLBFlutterViewContainer.new;
[vc setName:name params:params];
[self.navigationController pushViewController:vc animated:animated];
}
}
- (void)closePage:(NSString *)uid animated:(BOOL)animated params:(NSDictionary *)params completion:(void (^)(BOOL))completion
{
FLBFlutterViewContainer *vc = (id)self.navigationController.presentedViewController;
if([vc isKindOfClass:FLBFlutterViewContainer.class] && [vc.uniqueIDString isEqual: uid]){
[vc dismissViewControllerAnimated:animated completion:^{}];
}else{
[self.navigationController popViewControllerAnimated:animated];
}
}
@end
最后一步,在应用程序开头使用FLBPlatform初始化FlutterBoost:
[FlutterBoostPlugin.sharedInstance startFlutterWithPlatform:router
onStart:^(FlutterViewController * fvc){
}];
以下为集成flutter_boost踩坑记录
1.报错如下
解决方法如下:build phases → Embed Pods Frameworks → 勾选 show environment variables in build log,勾选 run script only when installing
2.报错如下:
报错原因:Flutter sdk版本过高,flutter_boost 尚未进行适配
解决方法:使用切换Flutter channel stable 分支,终端运行命令为:Flutter channel stable
3.运行成功后 native跳转Flutter后界面显示为空白
可能原因:继承了flutter_boost,没有注释这句代码引起,“[GeneratedPluginRegistrant registerWithRegistry:self];”flutter_boost内部会自动运行上述代码,如果没有注释上述代码会导致FlutterChannelManager初始化两次,继而将_methodChannels数组清空
解决方案:注释掉“[GeneratedPluginRegistrant registerWithRegistry:self];”
4.集成过程中,iOS的旧工程找不到Flutter_boost库文件。
解决方法:先注意下以下标红几个库的路径,如图:
知晓路径后,在旧项目的podfile中进行编辑,
pod 'flutter_boost', :path => '../flutter_module/.ios/Flutter/.symlinks/flutter_boost/ios'
pod 'xservice_kit', :path => '../flutter_module/.ios/Flutter/.symlinks/xservice_kit/ios'
如下图:
终端执行:
pod install