Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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
12extern 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.
17NSBundle* 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:]`.
33NSBundle* FLTFrameworkBundleWithIdentifier(NSString* flutterFrameworkBundleID);
34
35// Finds the bundle of the application.
36//
37// Returns [NSBundle mainBundle] if the current running process is the application.
38NSBundle* 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`.
43NSString* 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.
51NSString* FLTAssetsPathFromBundle(NSBundle* bundle);
52
54
55#endif // FLUTTER_SHELL_PLATFORM_DARWIN_COMMON_FRAMEWORK_SOURCE_FLUTTERNSBUNDLEUTILS_H_
#define NS_ASSUME_NONNULL_BEGIN
#define NS_ASSUME_NONNULL_END
NSBundle * FLTFrameworkBundleWithIdentifier(NSString *flutterFrameworkBundleID)
NSString * FLTAssetsPathFromBundle(NSBundle *bundle)
NSBundle * FLTGetApplicationBundle()
NS_ASSUME_NONNULL_BEGIN const NSString * kDefaultAssetPath
NSBundle * FLTFrameworkBundleInternal(NSString *flutterFrameworkBundleID, NSURL *searchURL)
NSString * FLTAssetPath(NSBundle *bundle)