| Flutter iOS Embedder |

Functions | Variables
FlutterNSBundleUtils.mm File Reference
`#import "flutter/shell/platform/darwin/common/framework/Source/FlutterNSBundleUtils.h"`
`#include <Foundation/Foundation.h>`
`#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h"`

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
FLUTTER_ASSERT_ARC NSString *const | kDefaultAssetPath = @"@"Frameworks/App.framework/flutter_assets"

## Function Documentation

## ◆ FLTAssetPath()

NSString* FLTAssetPath | ( | NSBundle * | bundle | ) |

Definition at line 60 of file FlutterNSBundleUtils.mm.

60 {
61 return [bundle objectForInfoDictionaryKey:@"FLTAssetsPath"] ?: kDefaultAssetPath;
62 }
kDefaultAssetPath
FLUTTER_ASSERT_ARC NSString *const kDefaultAssetPath
Definition: FlutterNSBundleUtils.mm:13

References kDefaultAssetPath.

Referenced by FLTAssetsPathFromBundle().

## ◆ FLTAssetsPathFromBundle()

NSString* FLTAssetsPathFromBundle | ( | NSBundle * | bundle | ) |

Definition at line 64 of file FlutterNSBundleUtils.mm.

64 {
65 NSString* relativeAssetsPath = FLTAssetPath(bundle);
66 NSString* flutterAssetsPath = GetFlutterAssetsPathFromBundle(bundle, relativeAssetsPath);
67 if (flutterAssetsPath.length == 0) {
68 flutterAssetsPath = GetFlutterAssetsPathFromBundle(NSBundle.mainBundle, relativeAssetsPath);
69 }
70 return flutterAssetsPath;
71 }
FLTAssetPath
NSString * FLTAssetPath(NSBundle *bundle)
Definition: FlutterNSBundleUtils.mm:60
GetFlutterAssetsPathFromBundle
static NSString * GetFlutterAssetsPathFromBundle(NSBundle *bundle, NSString *relativeAssetsPath)
Definition: FlutterNSBundleUtils.mm:73

References FLTAssetPath(), and GetFlutterAssetsPathFromBundle().

Referenced by FlutterDartProject::defaultBundleIdentifier.

## ◆ FLTFrameworkBundleInternal()

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

Definition at line 17 of file FlutterNSBundleUtils.mm.

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

Referenced by FLTFrameworkBundleWithIdentifier().

## ◆ FLTFrameworkBundleWithIdentifier()

NSBundle* FLTFrameworkBundleWithIdentifier | ( | NSString * | flutterFrameworkBundleID | ) |

Definition at line 46 of file FlutterNSBundleUtils.mm.

46 {
47 NSBundle* appBundle = FLTGetApplicationBundle();
48 NSBundle* flutterFrameworkBundle =
49 FLTFrameworkBundleInternal(flutterFrameworkBundleID, appBundle.privateFrameworksURL);
50 if (flutterFrameworkBundle == nil) {
51 // Fallback to slow implementation.
52 flutterFrameworkBundle = [NSBundle bundleWithIdentifier:flutterFrameworkBundleID];
53 }
54 if (flutterFrameworkBundle == nil) {
55 flutterFrameworkBundle = NSBundle.mainBundle;
56 }
57 return flutterFrameworkBundle;
58 }
FLTFrameworkBundleInternal
NSBundle * FLTFrameworkBundleInternal(NSString *flutterFrameworkBundleID, NSURL *searchURL)
Definition: FlutterNSBundleUtils.mm:17
FLTGetApplicationBundle
NSBundle * FLTGetApplicationBundle()
Definition: FlutterNSBundleUtils.mm:35

References FLTFrameworkBundleInternal(), and FLTGetApplicationBundle().

Referenced by FlutterDartProject::defaultBundleIdentifier.

## ◆ FLTGetApplicationBundle()

NSBundle* FLTGetApplicationBundle | ( |  | ) |

Definition at line 35 of file FlutterNSBundleUtils.mm.

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

Referenced by FlutterDartProject::defaultBundleIdentifier, and FLTFrameworkBundleWithIdentifier().

## ◆ GetFlutterAssetsPathFromBundle()

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

Definition at line 73 of file FlutterNSBundleUtils.mm.

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

Referenced by FLTAssetsPathFromBundle().

## Variable Documentation

## ◆ kDefaultAssetPath

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

Definition at line 13 of file FlutterNSBundleUtils.mm.

Referenced by FLTAssetPath().