From 2c06341258321c35c1083691b9eb7884cdb3216c Mon Sep 17 00:00:00 2001 From: Dan Field Date: Sat, 2 Mar 2019 10:01:51 -0800 Subject: [PATCH] Add overloads for lookup that lets you specify a bundle (flutter/engine#8007) * Add overloads for lookup that lets you specify a bundle * check bundle with defaultBundleIdentifier before main bundle --- .../framework/Headers/FlutterDartProject.h | 29 +++++++++++++++++-- .../framework/Source/FlutterDartProject.mm | 21 ++++++++++++-- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Headers/FlutterDartProject.h b/engine/src/flutter/shell/platform/darwin/ios/framework/Headers/FlutterDartProject.h index c2b4339d55..032d1c281f 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Headers/FlutterDartProject.h +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Headers/FlutterDartProject.h @@ -26,14 +26,26 @@ FLUTTER_EXPORT - (instancetype)initFromDefaultSourceForConfiguration FLUTTER_UNAVAILABLE("Use -init instead."); /** - * Returns the file name for the given asset. - * The returned file name can be used to access the asset in the application's main bundle. + * Returns the file name for the given asset. If the bundle with the identifier + * "io.flutter.flutter.app" exists, it will try use that bundle; otherwise, it + * will use the main bundle. To specify a different bundle, use + * `-lookupKeyForAsset:asset:fromBundle`. * * @param asset The name of the asset. The name can be hierarchical. * @return the file name to be used for lookup in the main bundle. */ + (NSString*)lookupKeyForAsset:(NSString*)asset; +/** + * Returns the file name for the given asset. + * The returned file name can be used to access the asset in the supplied bundle. + * + * @param asset The name of the asset. The name can be hierarchical. + * @param bundle The `NSBundle` to use for looking up the asset. + * @return the file name to be used for lookup in the main bundle. + */ ++ (NSString*)lookupKeyForAsset:(NSString*)asset fromBundle:(NSBundle*)bundle; + /** * Returns the file name for the given asset which originates from the specified package. * The returned file name can be used to access the asset in the application's main bundle. @@ -44,6 +56,19 @@ FLUTTER_EXPORT */ + (NSString*)lookupKeyForAsset:(NSString*)asset fromPackage:(NSString*)package; +/** + * Returns the file name for the given asset which originates from the specified package. + * The returned file name can be used to access the asset in the specified bundle. + * + * @param asset The name of the asset. The name can be hierarchical. + * @param package The name of the package from which the asset originates. + * @param bundle The bundle to use when doing the lookup. + * @return the file name to be used for lookup in the main bundle. + */ ++ (NSString*)lookupKeyForAsset:(NSString*)asset + fromPackage:(NSString*)package + fromBundle:(NSBundle*)bundle; + /** * Returns the default identifier for the bundle where we expect to find the Flutter Dart * application. diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm index 229e620aa6..4e0c97b3f1 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm @@ -199,6 +199,12 @@ static blink::Settings DefaultSettingsForProcess(NSBundle* bundle = nil) { #pragma mark - Assets-related utilities + (NSString*)flutterAssetsName:(NSBundle*)bundle { + if (bundle == nil) { + bundle = [NSBundle bundleWithIdentifier:[FlutterDartProject defaultBundleIdentifier]]; + } + if (bundle == nil) { + bundle = [NSBundle mainBundle]; + } NSString* flutterAssetsName = [bundle objectForInfoDictionaryKey:@"FLTAssetsPath"]; if (flutterAssetsName == nil) { flutterAssetsName = @"Frameworks/App.framework/flutter_assets"; @@ -207,12 +213,23 @@ static blink::Settings DefaultSettingsForProcess(NSBundle* bundle = nil) { } + (NSString*)lookupKeyForAsset:(NSString*)asset { - NSString* flutterAssetsName = [FlutterDartProject flutterAssetsName:[NSBundle mainBundle]]; + return [self lookupKeyForAsset:asset fromBundle:nil]; +} + ++ (NSString*)lookupKeyForAsset:(NSString*)asset fromBundle:(NSBundle*)bundle { + NSString* flutterAssetsName = [FlutterDartProject flutterAssetsName:bundle]; return [NSString stringWithFormat:@"%@/%@", flutterAssetsName, asset]; } + (NSString*)lookupKeyForAsset:(NSString*)asset fromPackage:(NSString*)package { - return [self lookupKeyForAsset:[NSString stringWithFormat:@"packages/%@/%@", package, asset]]; + return [self lookupKeyForAsset:asset fromPackage:package fromBundle:nil]; +} + ++ (NSString*)lookupKeyForAsset:(NSString*)asset + fromPackage:(NSString*)package + fromBundle:(NSBundle*)bundle { + return [self lookupKeyForAsset:[NSString stringWithFormat:@"packages/%@/%@", package, asset] + fromBundle:bundle]; } + (NSString*)defaultBundleIdentifier {