Flutter iOS Embedder
FlutterNSBundleUtils.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef FLUTTER_SHELL_PLATFORM_DARWIN_COMMON_FRAMEWORK_SOURCE_FLUTTERNSBUNDLEUTILS_H_
6 #define FLUTTER_SHELL_PLATFORM_DARWIN_COMMON_FRAMEWORK_SOURCE_FLUTTERNSBUNDLEUTILS_H_
7 
8 #import <Foundation/Foundation.h>
9 
11 
12 extern const NSString* kDefaultAssetPath;
13 
14 // Finds a bundle with the named `flutterFrameworkBundleID` within `searchURL`.
15 //
16 // Returns `nil` if the bundle cannot be found or if errors are encountered.
17 NSBundle* FLTFrameworkBundleInternal(NSString* flutterFrameworkBundleID, NSURL* searchURL);
18 
19 // Finds a bundle with the named `flutterFrameworkBundleID`.
20 //
21 // `+[NSBundle bundleWithIdentifier:]` is slow, and can take in the order of
22 // tens of milliseconds in a minimal flutter app, and closer to 100 milliseconds
23 // in a medium sized Flutter app on an iPhone 13. It is likely that the slowness
24 // comes from having to traverse and load all bundles known to the process.
25 // Using `+[NSBundle allframeworks]` and filtering also suffers from the same
26 // problem.
27 //
28 // This implementation is an optimization to first limit the search space to
29 // `+[NSBundle privateFrameworksURL]` of the main bundle, which is usually where
30 // frameworks used by this file are placed. If the desired bundle cannot be
31 // found here, the implementation falls back to
32 // `+[NSBundle bundleWithIdentifier:]`.
33 NSBundle* FLTFrameworkBundleWithIdentifier(NSString* flutterFrameworkBundleID);
34 
35 // Finds the bundle of the application.
36 //
37 // Returns [NSBundle mainBundle] if the current running process is the application.
38 NSBundle* FLTGetApplicationBundle();
39 
40 // Gets the flutter assets path directory from `bundle`.
41 //
42 // Returns `kDefaultAssetPath` if unable to find asset path from info.plist in `bundle`.
43 NSString* FLTAssetPath(NSBundle* bundle);
44 
45 // Finds the Flutter asset directory from `bundle`.
46 //
47 // The raw path can be set by the application via info.plist's `FLTAssetsPath` key.
48 // If the key is not set, `flutter_assets` is used as the raw path value.
49 //
50 // If no valid asset is found under the raw path, returns nil.
51 NSString* FLTAssetsPathFromBundle(NSBundle* bundle);
52 
54 
55 #endif // FLUTTER_SHELL_PLATFORM_DARWIN_COMMON_FRAMEWORK_SOURCE_FLUTTERNSBUNDLEUTILS_H_
FLTFrameworkBundleInternal
NSBundle * FLTFrameworkBundleInternal(NSString *flutterFrameworkBundleID, NSURL *searchURL)
Definition: FlutterNSBundleUtils.mm:14
NS_ASSUME_NONNULL_END
#define NS_ASSUME_NONNULL_END
Definition: FlutterMacros.h:20
NS_ASSUME_NONNULL_BEGIN
#define NS_ASSUME_NONNULL_BEGIN
Definition: FlutterMacros.h:19
FLTAssetPath
NSString * FLTAssetPath(NSBundle *bundle)
Definition: FlutterNSBundleUtils.mm:57
kDefaultAssetPath
const NS_ASSUME_NONNULL_BEGIN NSString * kDefaultAssetPath
Definition: FlutterNSBundleUtils.mm:11
FLTGetApplicationBundle
NSBundle * FLTGetApplicationBundle()
Definition: FlutterNSBundleUtils.mm:32
FLTFrameworkBundleWithIdentifier
NSBundle * FLTFrameworkBundleWithIdentifier(NSString *flutterFrameworkBundleID)
Definition: FlutterNSBundleUtils.mm:43
FLTAssetsPathFromBundle
NSString * FLTAssetsPathFromBundle(NSBundle *bundle)
Definition: FlutterNSBundleUtils.mm:61