0x0 使用自定义bundle
调用 -[FlutterViewController initWithProject:nibName:bundle:]传入自定义bundle
使用FlutterAppDelegate的话可以用分类覆盖initWithCoder:
@implementation FlutterViewController (Custom)
- (instancetype)initWithCoder:(NSCoder *)coder
{
//这里传入bundle
NSString *path = [NSString stringWithFormat:@"%@/FlutterAsset.bundle",[[NSBundle mainBundle] bundlePath]];
NSBundle *bundle = [NSBundle bundleWithPath:path];
id proj = [[FlutterDartProject alloc] initWithPrecompiledDartBundle:bundle];
return [self initWithProject:proj nibName:nil bundle:nil];
}
@end
Bundle中的InfoPlist要一个Key FLTAssetsPath Value为自定义flutter_assets的路径
如flutter_assets
否则会去mainBundle中查找Frameworks/App.framework/flutter_assets
最终修改settings.application_kernel_asset
bundle结构如下
![](https://img.haomeiwen.com/i6000430/ba4111485fb4f813.png)
中间还有个条件!flutter::DartVM::IsRunningPrecompiledCode(),看起来是保证编译过程中不会修改路径
demo工程https://github.com/Kila2/flutter_custom_asset_path_example
网友评论