63 bool hasExplicitBundle = bundle != nil;
80 settings.log_message_callback = [](
const std::string& tag,
const std::string&
message) {
81 std::stringstream stream;
83 stream << tag <<
": ";
86 std::string log = stream.str();
87 [FlutterLogger logDirect:[NSString stringWithUTF8String:log.c_str()]];
90 settings.enable_platform_isolates =
true;
96 if (settings.icu_data_path.empty()) {
97 NSString* icuDataPath = [engineBundle pathForResource:
@"icudtl" ofType:
@"dat"];
98 if (icuDataPath.length > 0) {
99 settings.icu_data_path = icuDataPath.UTF8String;
104 if (hasExplicitBundle) {
105 NSString* executablePath = bundle.executablePath;
106 if ([[NSFileManager defaultManager] fileExistsAtPath:executablePath]) {
107 settings.application_library_paths.push_back(executablePath.UTF8String);
112 if (settings.application_library_paths.empty()) {
113 NSString* libraryName = [mainBundle objectForInfoDictionaryKey:
@"FLTLibraryPath"];
114 NSString* libraryPath = [mainBundle pathForResource:libraryName ofType:
@""];
115 if (libraryPath.length > 0) {
116 NSString* executablePath = [NSBundle bundleWithPath:libraryPath].executablePath;
117 if (executablePath.length > 0) {
118 settings.application_library_paths.push_back(executablePath.UTF8String);
125 if (settings.application_library_paths.empty()) {
126 NSString* applicationFrameworkPath = [mainBundle pathForResource:
@"Frameworks/App.framework"
128 if (applicationFrameworkPath.length > 0) {
129 NSString* executablePath =
130 [NSBundle bundleWithPath:applicationFrameworkPath].executablePath;
131 if (executablePath.length > 0) {
132 settings.application_library_paths.push_back(executablePath.UTF8String);
139 if (settings.assets_path.empty()) {
142 if (assetsPath.length == 0) {
143 NSLog(
@"Failed to find assets path for \"%@\
"", bundle);
145 settings.assets_path = assetsPath.UTF8String;
151 NSURL* applicationKernelSnapshotURL =
153 relativeToURL:[NSURL fileURLWithPath:assetsPath]];
155 if ([applicationKernelSnapshotURL checkResourceIsReachableAndReturnError:&
error]) {
156 settings.application_kernel_asset = applicationKernelSnapshotURL.path.UTF8String;
158 NSLog(
@"Failed to find snapshot at %@: %@", applicationKernelSnapshotURL.path,
error);
167 settings.may_insecurely_connect_to_all_domains =
true;
168 settings.domain_network_policy =
"";
171#if TARGET_OS_SIMULATOR
174 settings.enable_wide_gamut =
false;
179 BOOL enableWideGamut =
181 settings.enable_wide_gamut = enableWideGamut;
184 settings.warn_on_impeller_opt_out =
true;
186 NSNumber* nsEnableSDFs = [mainBundle objectForInfoDictionaryKey:
@"FLTEnableSDFs"];
187 settings.impeller_use_sdfs = (nsEnableSDFs ? nsEnableSDFs.boolValue : NO);
189 NSNumber* enableTraceSystrace = [mainBundle objectForInfoDictionaryKey:
@"FLTTraceSystrace"];
191 if (enableTraceSystrace != nil) {
192 settings.trace_systrace = enableTraceSystrace.boolValue;
195 NSNumber* profileMicrotasks = [mainBundle objectForInfoDictionaryKey:
@"FLTProfileMicrotasks"];
197 if (profileMicrotasks != nil) {
198 settings.profile_microtasks = profileMicrotasks.boolValue;
201 NSNumber* enableDartAsserts = [mainBundle objectForInfoDictionaryKey:
@"FLTEnableDartAsserts"];
202 if (enableDartAsserts != nil) {
203 settings.dart_flags.push_back(
"--enable-asserts");
206 NSNumber* enableDartProfiling = [mainBundle objectForInfoDictionaryKey:
@"FLTEnableDartProfiling"];
208 if (enableDartProfiling != nil) {
209 settings.enable_dart_profiling = enableDartProfiling.boolValue;
212 NSNumber* profileStartup = [mainBundle objectForInfoDictionaryKey:
@"FLTProfileStartup"];
214 if (profileStartup != nil) {
215 settings.profile_startup = profileStartup.boolValue;
219 NSNumber* leakDartVM = [mainBundle objectForInfoDictionaryKey:
@"FLTLeakDartVM"];
221 if (leakDartVM != nil) {
222 settings.leak_vm = leakDartVM.boolValue;
225 NSNumber* enableMergedPlatformUIThread =
226 [mainBundle objectForInfoDictionaryKey:
@"FLTEnableMergedPlatformUIThread"];
227 if (enableMergedPlatformUIThread != nil) {
228 FML_CHECK(enableMergedPlatformUIThread.boolValue)
229 <<
"FLTEnableMergedPlatformUIThread=false is no longer allowed.";
232 NSNumber* enableFlutterGPU = [mainBundle objectForInfoDictionaryKey:
@"FLTEnableFlutterGPU"];
233 if (enableFlutterGPU != nil) {
234 settings.enable_flutter_gpu = enableFlutterGPU.boolValue;
237#if FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG
240 auto make_mapping_callback = [](
const uint8_t* mapping,
size_t size) {
241 return [mapping, size]() {
return std::make_unique<fml::NonOwnedMapping>(mapping, size); };
244 settings.dart_library_sources_kernel =
254 if (settings.old_gen_heap_size <= 0) {
255 settings.old_gen_heap_size = std::round([NSProcessInfo processInfo].physicalMemory * .48 /
261 CGFloat scale = [UIScreen mainScreen].scale;
262 CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width * scale;
263 CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height * scale;
264 settings.resource_cache_max_bytes_threshold = screenWidth * screenHeight * 12 * 4;
267 NSNumber* enable_embedder_api =
268 [mainBundle objectForInfoDictionaryKey:
@"FLTEnableIOSEmbedderAPI"];
270 if (enable_embedder_api) {
271 settings.enable_embedder_api = enable_embedder_api.boolValue;
284@dynamic dartEntrypointArguments;
286#pragma mark - Override base class designated initializers
288- (instancetype)init {
289 return [
self initWithPrecompiledDartBundle:nil];
292#pragma mark - Designated initializers
294- (instancetype)initWithPrecompiledDartBundle:(nullable NSBundle*)bundle {
304- (instancetype)initWithSettings:(const
flutter::Settings&)settings {
305 self = [
self initWithPrecompiledDartBundle:nil];
308 _settings = settings;
314#pragma mark - PlatformData accessors
316- (const
flutter::PlatformData)defaultPlatformData {
318 PlatformData.
lifecycle_state = std::string(
"AppLifecycleState.detached");
322#pragma mark - Settings accessors
324- (const
flutter::Settings&)settings {
328- (
flutter::RunConfiguration)runConfiguration {
329 return [
self runConfigurationForEntrypoint:nil];
332- (
flutter::RunConfiguration)runConfigurationForEntrypoint:(nullable NSString*)entrypointOrNil {
333 return [
self runConfigurationForEntrypoint:entrypointOrNil libraryOrNil:nil];
336- (
flutter::RunConfiguration)runConfigurationForEntrypoint:(nullable NSString*)entrypointOrNil
337 libraryOrNil:(nullable NSString*)dartLibraryOrNil {
338 return [
self runConfigurationForEntrypoint:entrypointOrNil
339 libraryOrNil:dartLibraryOrNil
343- (
flutter::RunConfiguration)runConfigurationForEntrypoint:(nullable NSString*)entrypointOrNil
344 libraryOrNil:(nullable NSString*)dartLibraryOrNil
346 (nullable NSArray<NSString*>*)entrypointArgs {
348 if (dartLibraryOrNil && entrypointOrNil) {
349 config.SetEntrypointAndLibrary(std::string([entrypointOrNil UTF8String]),
350 std::string([dartLibraryOrNil UTF8String]));
352 }
else if (entrypointOrNil) {
353 config.SetEntrypoint(std::string([entrypointOrNil UTF8String]));
356 if (entrypointArgs.count) {
357 std::vector<std::string> cppEntrypointArgs;
358 for (NSString* arg in entrypointArgs) {
359 cppEntrypointArgs.push_back(std::string([arg UTF8String]));
361 config.SetEntrypointArgs(std::move(cppEntrypointArgs));
367#pragma mark - Assets-related utilities
369+ (NSString*)flutterAssetsName:(NSBundle*)bundle {
376+ (NSString*)domainNetworkPolicy:(NSDictionary*)appTransportSecurity {
378 NSDictionary* exceptionDomains = appTransportSecurity[@"NSExceptionDomains"];
379 if (exceptionDomains == nil) {
382 NSMutableArray* networkConfigArray = [[NSMutableArray alloc] init];
383 for (NSString* domain in exceptionDomains) {
384 NSDictionary* domainConfiguration = exceptionDomains[domain];
386 bool includesSubDomains = [domainConfiguration[@"NSIncludesSubdomains"] boolValue];
387 bool allowsCleartextCommunication =
388 [domainConfiguration[@"NSExceptionAllowsInsecureHTTPLoads"] boolValue];
389 [networkConfigArray addObject:@[
390 domain, includesSubDomains ? @YES : @NO, allowsCleartextCommunication ? @YES : @NO
393 NSData* jsonData = [NSJSONSerialization dataWithJSONObject:networkConfigArray
396 return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
399+ (bool)allowsArbitraryLoads:(NSDictionary*)appTransportSecurity {
400 return [appTransportSecurity[@"NSAllowsArbitraryLoads"] boolValue];
403+ (NSString*)lookupKeyForAsset:(NSString*)asset {
404 return [
self lookupKeyForAsset:asset fromBundle:nil];
407+ (NSString*)lookupKeyForAsset:(NSString*)asset fromBundle:(nullable NSBundle*)bundle {
409 return [NSString stringWithFormat:@"%@/%@", flutterAssetsName, asset];
412+ (NSString*)lookupKeyForAsset:(NSString*)asset fromPackage:(NSString*)package {
413 return [
self lookupKeyForAsset:asset fromPackage:package fromBundle:nil];
416+ (NSString*)lookupKeyForAsset:(NSString*)asset
417 fromPackage:(NSString*)package
418 fromBundle:(nullable NSBundle*)bundle {
419 return [
self lookupKeyForAsset:[NSString stringWithFormat:@"packages/%@/%@", package, asset]
423+ (NSString*)defaultBundleIdentifier {
424 return @"io.flutter.flutter.app";