diff --git a/shell/platform/darwin/ios/framework/Headers/FlutterDartProject.h b/shell/platform/darwin/ios/framework/Headers/FlutterDartProject.h index c2b4339d55b33dba6089ea2a7378cb93941b04e3..032d1c281f3a26421dadcf29e0f6d97e8027ec0c 100644 --- a/shell/platform/darwin/ios/framework/Headers/FlutterDartProject.h +++ b/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/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm b/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm index 229e620aa618447682432a68253661f3cdb3d912..4e0c97b3f113aba7ea3b8ed02cbcda39abc67a1c 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm +++ b/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 {