Flutter iOS Embedder
FlutterNSBundleUtils.mm File Reference

Go to the source code of this file.

Functions

static NSString * GetFlutterAssetsPathFromBundle (NSBundle *bundle, NSString *relativeAssetsPath)
 
NSBundle * FLTFrameworkBundleInternal (NSString *flutterFrameworkBundleID, NSURL *searchURL)
 
NSBundle * FLTGetApplicationBundle ()
 
NSBundle * FLTFrameworkBundleWithIdentifier (NSString *flutterFrameworkBundleID)
 
NSString * FLTAssetPath (NSBundle *bundle)
 
NSString * FLTAssetsPathFromBundle (NSBundle *bundle)
 

Variables

const FLUTTER_ASSERT_ARC NSString * kDefaultAssetPath = @"@"Frameworks/App.framework/flutter_assets"
 

Function Documentation

◆ FLTAssetPath()

NSString* FLTAssetPath ( NSBundle *  bundle)

Definition at line 57 of file FlutterNSBundleUtils.mm.

57  {
58  return [bundle objectForInfoDictionaryKey:@"FLTAssetsPath"] ?: kDefaultAssetPath;
59 }

References kDefaultAssetPath.

Referenced by FLTAssetsPathFromBundle().

◆ FLTAssetsPathFromBundle()

NSString* FLTAssetsPathFromBundle ( NSBundle *  bundle)

Definition at line 61 of file FlutterNSBundleUtils.mm.

61  {
62  NSString* relativeAssetsPath = FLTAssetPath(bundle);
63  NSString* flutterAssetsPath = GetFlutterAssetsPathFromBundle(bundle, relativeAssetsPath);
64  if (flutterAssetsPath.length == 0) {
65  flutterAssetsPath = GetFlutterAssetsPathFromBundle(NSBundle.mainBundle, relativeAssetsPath);
66  }
67  return flutterAssetsPath;
68 }

References FLTAssetPath(), and GetFlutterAssetsPathFromBundle().

Referenced by FLTDefaultSettingsForBundle().

◆ FLTFrameworkBundleInternal()

NSBundle* FLTFrameworkBundleInternal ( NSString *  flutterFrameworkBundleID,
NSURL *  searchURL 
)

Definition at line 14 of file FlutterNSBundleUtils.mm.

14  {
15  NSDirectoryEnumerator<NSURL*>* frameworkEnumerator = [NSFileManager.defaultManager
16  enumeratorAtURL:searchURL
17  includingPropertiesForKeys:nil
18  options:NSDirectoryEnumerationSkipsSubdirectoryDescendants |
19  NSDirectoryEnumerationSkipsHiddenFiles
20  // Skip directories where errors are encountered.
21  errorHandler:nil];
22 
23  for (NSURL* candidate in frameworkEnumerator) {
24  NSBundle* flutterFrameworkBundle = [NSBundle bundleWithURL:candidate];
25  if ([flutterFrameworkBundle.bundleIdentifier isEqualToString:flutterFrameworkBundleID]) {
26  return flutterFrameworkBundle;
27  }
28  }
29  return nil;
30 }

Referenced by FLTFrameworkBundleWithIdentifier().

◆ FLTFrameworkBundleWithIdentifier()

NSBundle* FLTFrameworkBundleWithIdentifier ( NSString *  flutterFrameworkBundleID)

Definition at line 43 of file FlutterNSBundleUtils.mm.

43  {
44  NSBundle* appBundle = FLTGetApplicationBundle();
45  NSBundle* flutterFrameworkBundle =
46  FLTFrameworkBundleInternal(flutterFrameworkBundleID, appBundle.privateFrameworksURL);
47  if (flutterFrameworkBundle == nil) {
48  // Fallback to slow implementation.
49  flutterFrameworkBundle = [NSBundle bundleWithIdentifier:flutterFrameworkBundleID];
50  }
51  if (flutterFrameworkBundle == nil) {
52  flutterFrameworkBundle = NSBundle.mainBundle;
53  }
54  return flutterFrameworkBundle;
55 }

References FLTFrameworkBundleInternal(), and FLTGetApplicationBundle().

Referenced by FLTDefaultSettingsForBundle().

◆ FLTGetApplicationBundle()

NSBundle* FLTGetApplicationBundle ( )

Definition at line 32 of file FlutterNSBundleUtils.mm.

32  {
33  NSBundle* mainBundle = NSBundle.mainBundle;
34  // App extension bundle is in <AppName>.app/PlugIns/Extension.appex.
35  if ([mainBundle.bundleURL.pathExtension isEqualToString:@"appex"]) {
36  // Up two levels.
37  return [NSBundle bundleWithURL:mainBundle.bundleURL.URLByDeletingLastPathComponent
38  .URLByDeletingLastPathComponent];
39  }
40  return mainBundle;
41 }

Referenced by FLTDefaultSettingsForBundle(), and FLTFrameworkBundleWithIdentifier().

◆ GetFlutterAssetsPathFromBundle()

static NSString * GetFlutterAssetsPathFromBundle ( NSBundle *  bundle,
NSString *  relativeAssetsPath 
)
static

Definition at line 70 of file FlutterNSBundleUtils.mm.

70  {
71  // Use the raw path solution so that asset path can be returned from unloaded bundles.
72  // See https://github.com/flutter/engine/pull/46073
73  NSString* assetsPath = [bundle pathForResource:relativeAssetsPath ofType:nil];
74  if (assetsPath.length == 0) {
75  // In app extension, using full relative path (kDefaultAssetPath)
76  // returns nil when the app bundle is not loaded. Try to use
77  // the sub folder name, which can successfully return a valid path.
78  assetsPath = [bundle pathForResource:@"flutter_assets" ofType:nil];
79  }
80  return assetsPath;
81 }

Referenced by FLTAssetsPathFromBundle().

Variable Documentation

◆ kDefaultAssetPath

const FLUTTER_ASSERT_ARC NSString* kDefaultAssetPath = @"@"Frameworks/App.framework/flutter_assets"

Definition at line 11 of file FlutterNSBundleUtils.mm.

Referenced by FLTAssetPath().

FLTFrameworkBundleInternal
NSBundle * FLTFrameworkBundleInternal(NSString *flutterFrameworkBundleID, NSURL *searchURL)
Definition: FlutterNSBundleUtils.mm:14
GetFlutterAssetsPathFromBundle
static NSString * GetFlutterAssetsPathFromBundle(NSBundle *bundle, NSString *relativeAssetsPath)
Definition: FlutterNSBundleUtils.mm:70
FLTAssetPath
NSString * FLTAssetPath(NSBundle *bundle)
Definition: FlutterNSBundleUtils.mm:57
kDefaultAssetPath
const FLUTTER_ASSERT_ARC NSString * kDefaultAssetPath
Definition: FlutterNSBundleUtils.mm:11
FLTGetApplicationBundle
NSBundle * FLTGetApplicationBundle()
Definition: FlutterNSBundleUtils.mm:32