54 bool hasExplicitBundle = bundle != nil;
71 settings.log_message_callback = [](
const std::string& tag,
const std::string&
message) {
72 std::stringstream stream;
74 stream << tag <<
": ";
77 std::string log = stream.str();
78 [FlutterLogger logDirect:[NSString stringWithUTF8String:log.c_str()]];
81 settings.enable_platform_isolates =
true;
87 if (settings.icu_data_path.empty()) {
88 NSString* icuDataPath = [engineBundle pathForResource:
@"icudtl" ofType:
@"dat"];
89 if (icuDataPath.length > 0) {
90 settings.icu_data_path = icuDataPath.UTF8String;
95 if (hasExplicitBundle) {
96 NSString* executablePath = bundle.executablePath;
97 if ([[NSFileManager defaultManager] fileExistsAtPath:executablePath]) {
98 settings.application_library_paths.push_back(executablePath.UTF8String);
103 if (settings.application_library_paths.empty()) {
104 NSString* libraryName = [mainBundle objectForInfoDictionaryKey:
@"FLTLibraryPath"];
105 NSString* libraryPath = [mainBundle pathForResource:libraryName ofType:
@""];
106 if (libraryPath.length > 0) {
107 NSString* executablePath = [NSBundle bundleWithPath:libraryPath].executablePath;
108 if (executablePath.length > 0) {
109 settings.application_library_paths.push_back(executablePath.UTF8String);
116 if (settings.application_library_paths.empty()) {
117 NSString* applicationFrameworkPath = [mainBundle pathForResource:
@"Frameworks/App.framework"
119 if (applicationFrameworkPath.length > 0) {
120 NSString* executablePath =
121 [NSBundle bundleWithPath:applicationFrameworkPath].executablePath;
122 if (executablePath.length > 0) {
123 settings.application_library_paths.push_back(executablePath.UTF8String);
130 if (settings.assets_path.empty()) {
133 if (assetsPath.length == 0) {
134 NSLog(
@"Failed to find assets path for \"%@\
"", bundle);
136 settings.assets_path = assetsPath.UTF8String;
142 NSURL* applicationKernelSnapshotURL =
144 relativeToURL:[NSURL fileURLWithPath:assetsPath]];
146 if ([applicationKernelSnapshotURL checkResourceIsReachableAndReturnError:&
error]) {
147 settings.application_kernel_asset = applicationKernelSnapshotURL.path.UTF8String;
149 NSLog(
@"Failed to find snapshot at %@: %@", applicationKernelSnapshotURL.path,
error);
158 settings.may_insecurely_connect_to_all_domains =
true;
159 settings.domain_network_policy =
"";
162#if TARGET_OS_SIMULATOR
165 settings.enable_wide_gamut =
false;
169 NSNumber* nsEnableWideGamut = [mainBundle objectForInfoDictionaryKey:
@"FLTEnableWideGamut"];
170 BOOL enableWideGamut =
172 settings.enable_wide_gamut = enableWideGamut;
175 NSNumber* nsAntialiasLines = [mainBundle objectForInfoDictionaryKey:
@"FLTAntialiasLines"];
176 settings.impeller_antialiased_lines = (nsAntialiasLines ? nsAntialiasLines.boolValue : NO);
178 settings.warn_on_impeller_opt_out =
true;
180 NSNumber* nsEnableSDFs = [mainBundle objectForInfoDictionaryKey:
@"FLTEnableSDFs"];
181 settings.impeller_use_sdfs = (nsEnableSDFs ? nsEnableSDFs.boolValue : NO);
183 NSNumber* enableTraceSystrace = [mainBundle objectForInfoDictionaryKey:
@"FLTTraceSystrace"];
185 if (enableTraceSystrace != nil) {
186 settings.trace_systrace = enableTraceSystrace.boolValue;
189 NSNumber* profileMicrotasks = [mainBundle objectForInfoDictionaryKey:
@"FLTProfileMicrotasks"];
191 if (profileMicrotasks != nil) {
192 settings.profile_microtasks = profileMicrotasks.boolValue;
195 NSNumber* enableDartAsserts = [mainBundle objectForInfoDictionaryKey:
@"FLTEnableDartAsserts"];
196 if (enableDartAsserts != nil) {
197 settings.dart_flags.push_back(
"--enable-asserts");
200 NSNumber* enableDartProfiling = [mainBundle objectForInfoDictionaryKey:
@"FLTEnableDartProfiling"];
202 if (enableDartProfiling != nil) {
203 settings.enable_dart_profiling = enableDartProfiling.boolValue;
206 NSNumber* profileStartup = [mainBundle objectForInfoDictionaryKey:
@"FLTProfileStartup"];
208 if (profileStartup != nil) {
209 settings.profile_startup = profileStartup.boolValue;
213 NSNumber* leakDartVM = [mainBundle objectForInfoDictionaryKey:
@"FLTLeakDartVM"];
215 if (leakDartVM != nil) {
216 settings.leak_vm = leakDartVM.boolValue;
219 NSNumber* enableMergedPlatformUIThread =
220 [mainBundle objectForInfoDictionaryKey:
@"FLTEnableMergedPlatformUIThread"];
221 if (enableMergedPlatformUIThread != nil) {
222 FML_CHECK(enableMergedPlatformUIThread.boolValue)
223 <<
"FLTEnableMergedPlatformUIThread=false is no longer allowed.";
226 NSNumber* enableFlutterGPU = [mainBundle objectForInfoDictionaryKey:
@"FLTEnableFlutterGPU"];
227 if (enableFlutterGPU != nil) {
228 settings.enable_flutter_gpu = enableFlutterGPU.boolValue;
231#if FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG
234 auto make_mapping_callback = [](
const uint8_t* mapping,
size_t size) {
235 return [mapping, size]() {
return std::make_unique<fml::NonOwnedMapping>(mapping, size); };
238 settings.dart_library_sources_kernel =
248 if (settings.old_gen_heap_size <= 0) {
249 settings.old_gen_heap_size = std::round([NSProcessInfo processInfo].physicalMemory * .48 /
255 CGFloat scale = [UIScreen mainScreen].scale;
256 CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width * scale;
257 CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height * scale;
258 settings.resource_cache_max_bytes_threshold = screenWidth * screenHeight * 12 * 4;
261 NSNumber* enable_embedder_api =
262 [mainBundle objectForInfoDictionaryKey:
@"FLTEnableIOSEmbedderAPI"];
264 if (enable_embedder_api) {
265 settings.enable_embedder_api = enable_embedder_api.boolValue;
278@dynamic dartEntrypointArguments;
280#pragma mark - Override base class designated initializers
282- (instancetype)init {
283 return [
self initWithPrecompiledDartBundle:nil];
286#pragma mark - Designated initializers
288- (instancetype)initWithPrecompiledDartBundle:(nullable NSBundle*)bundle {
298- (instancetype)initWithSettings:(const
flutter::Settings&)settings {
299 self = [
self initWithPrecompiledDartBundle:nil];
302 _settings = settings;
308#pragma mark - PlatformData accessors
310- (const
flutter::PlatformData)defaultPlatformData {
312 PlatformData.
lifecycle_state = std::string(
"AppLifecycleState.detached");
316#pragma mark - Settings accessors
318- (const
flutter::Settings&)settings {
322- (
flutter::RunConfiguration)runConfiguration {
323 return [
self runConfigurationForEntrypoint:nil];
326- (
flutter::RunConfiguration)runConfigurationForEntrypoint:(nullable NSString*)entrypointOrNil {
327 return [
self runConfigurationForEntrypoint:entrypointOrNil libraryOrNil:nil];
330- (
flutter::RunConfiguration)runConfigurationForEntrypoint:(nullable NSString*)entrypointOrNil
331 libraryOrNil:(nullable NSString*)dartLibraryOrNil {
332 return [
self runConfigurationForEntrypoint:entrypointOrNil
333 libraryOrNil:dartLibraryOrNil
337- (
flutter::RunConfiguration)runConfigurationForEntrypoint:(nullable NSString*)entrypointOrNil
338 libraryOrNil:(nullable NSString*)dartLibraryOrNil
340 (nullable NSArray<NSString*>*)entrypointArgs {
342 if (dartLibraryOrNil && entrypointOrNil) {
343 config.SetEntrypointAndLibrary(std::string([entrypointOrNil UTF8String]),
344 std::string([dartLibraryOrNil UTF8String]));
346 }
else if (entrypointOrNil) {
347 config.SetEntrypoint(std::string([entrypointOrNil UTF8String]));
350 if (entrypointArgs.count) {
351 std::vector<std::string> cppEntrypointArgs;
352 for (NSString* arg in entrypointArgs) {
353 cppEntrypointArgs.push_back(std::string([arg UTF8String]));
355 config.SetEntrypointArgs(std::move(cppEntrypointArgs));
361#pragma mark - Assets-related utilities
363+ (NSString*)flutterAssetsName:(NSBundle*)bundle {
370+ (NSString*)domainNetworkPolicy:(NSDictionary*)appTransportSecurity {
372 NSDictionary* exceptionDomains = appTransportSecurity[@"NSExceptionDomains"];
373 if (exceptionDomains == nil) {
376 NSMutableArray* networkConfigArray = [[NSMutableArray alloc] init];
377 for (NSString* domain in exceptionDomains) {
378 NSDictionary* domainConfiguration = exceptionDomains[domain];
380 bool includesSubDomains = [domainConfiguration[@"NSIncludesSubdomains"] boolValue];
381 bool allowsCleartextCommunication =
382 [domainConfiguration[@"NSExceptionAllowsInsecureHTTPLoads"] boolValue];
383 [networkConfigArray addObject:@[
384 domain, includesSubDomains ? @YES : @NO, allowsCleartextCommunication ? @YES : @NO
387 NSData* jsonData = [NSJSONSerialization dataWithJSONObject:networkConfigArray
390 return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
393+ (bool)allowsArbitraryLoads:(NSDictionary*)appTransportSecurity {
394 return [appTransportSecurity[@"NSAllowsArbitraryLoads"] boolValue];
397+ (NSString*)lookupKeyForAsset:(NSString*)asset {
398 return [
self lookupKeyForAsset:asset fromBundle:nil];
401+ (NSString*)lookupKeyForAsset:(NSString*)asset fromBundle:(nullable NSBundle*)bundle {
403 return [NSString stringWithFormat:@"%@/%@", flutterAssetsName, asset];
406+ (NSString*)lookupKeyForAsset:(NSString*)asset fromPackage:(NSString*)package {
407 return [
self lookupKeyForAsset:asset fromPackage:package fromBundle:nil];
410+ (NSString*)lookupKeyForAsset:(NSString*)asset
411 fromPackage:(NSString*)package
412 fromBundle:(nullable NSBundle*)bundle {
413 return [
self lookupKeyForAsset:[NSString stringWithFormat:@"packages/%@/%@", package, asset]
417+ (NSString*)defaultBundleIdentifier {
418 return @"io.flutter.flutter.app";