未验证 提交 13064aec 编写于 作者: D Dan Field 提交者: GitHub

Add overloads for lookup that lets you specify a bundle (#8007)

* Add overloads for lookup that lets you specify a bundle

* check bundle with defaultBundleIdentifier before main bundle
上级 130cf77c
......@@ -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.
......
......@@ -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 {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册