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* enableTraceSystrace = [mainBundle objectForInfoDictionaryKey:
@"FLTTraceSystrace"];
182 if (enableTraceSystrace != nil) {
183 settings.trace_systrace = enableTraceSystrace.boolValue;
186 NSNumber* profileMicrotasks = [mainBundle objectForInfoDictionaryKey:
@"FLTProfileMicrotasks"];
188 if (profileMicrotasks != nil) {
189 settings.profile_microtasks = profileMicrotasks.boolValue;
192 NSNumber* enableDartAsserts = [mainBundle objectForInfoDictionaryKey:
@"FLTEnableDartAsserts"];
193 if (enableDartAsserts != nil) {
194 settings.dart_flags.push_back(
"--enable-asserts");
197 NSNumber* enableDartProfiling = [mainBundle objectForInfoDictionaryKey:
@"FLTEnableDartProfiling"];
199 if (enableDartProfiling != nil) {
200 settings.enable_dart_profiling = enableDartProfiling.boolValue;
203 NSNumber* profileStartup = [mainBundle objectForInfoDictionaryKey:
@"FLTProfileStartup"];
205 if (profileStartup != nil) {
206 settings.profile_startup = profileStartup.boolValue;
210 NSNumber* leakDartVM = [mainBundle objectForInfoDictionaryKey:
@"FLTLeakDartVM"];
212 if (leakDartVM != nil) {
213 settings.leak_vm = leakDartVM.boolValue;
216 NSNumber* enableMergedPlatformUIThread =
217 [mainBundle objectForInfoDictionaryKey:
@"FLTEnableMergedPlatformUIThread"];
218 if (enableMergedPlatformUIThread != nil) {
219 FML_CHECK(enableMergedPlatformUIThread.boolValue)
220 <<
"FLTEnableMergedPlatformUIThread=false is no longer allowed.";
223 NSNumber* enableFlutterGPU = [mainBundle objectForInfoDictionaryKey:
@"FLTEnableFlutterGPU"];
224 if (enableFlutterGPU != nil) {
225 settings.enable_flutter_gpu = enableFlutterGPU.boolValue;
228#if FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG
231 auto make_mapping_callback = [](
const uint8_t* mapping,
size_t size) {
232 return [mapping, size]() {
return std::make_unique<fml::NonOwnedMapping>(mapping, size); };
235 settings.dart_library_sources_kernel =
245 if (settings.old_gen_heap_size <= 0) {
246 settings.old_gen_heap_size = std::round([NSProcessInfo processInfo].physicalMemory * .48 /
252 CGFloat scale = [UIScreen mainScreen].scale;
253 CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width * scale;
254 CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height * scale;
255 settings.resource_cache_max_bytes_threshold = screenWidth * screenHeight * 12 * 4;
258 NSNumber* enable_embedder_api =
259 [mainBundle objectForInfoDictionaryKey:
@"FLTEnableIOSEmbedderAPI"];
261 if (enable_embedder_api) {
262 settings.enable_embedder_api = enable_embedder_api.boolValue;
275@dynamic dartEntrypointArguments;
277#pragma mark - Override base class designated initializers
279- (instancetype)init {
280 return [
self initWithPrecompiledDartBundle:nil];
283#pragma mark - Designated initializers
285- (instancetype)initWithPrecompiledDartBundle:(nullable NSBundle*)bundle {
295- (instancetype)initWithSettings:(const
flutter::Settings&)settings {
296 self = [
self initWithPrecompiledDartBundle:nil];
299 _settings = settings;
305#pragma mark - PlatformData accessors
307- (const
flutter::PlatformData)defaultPlatformData {
309 PlatformData.
lifecycle_state = std::string(
"AppLifecycleState.detached");
313#pragma mark - Settings accessors
315- (const
flutter::Settings&)settings {
319- (
flutter::RunConfiguration)runConfiguration {
320 return [
self runConfigurationForEntrypoint:nil];
323- (
flutter::RunConfiguration)runConfigurationForEntrypoint:(nullable NSString*)entrypointOrNil {
324 return [
self runConfigurationForEntrypoint:entrypointOrNil libraryOrNil:nil];
327- (
flutter::RunConfiguration)runConfigurationForEntrypoint:(nullable NSString*)entrypointOrNil
328 libraryOrNil:(nullable NSString*)dartLibraryOrNil {
329 return [
self runConfigurationForEntrypoint:entrypointOrNil
330 libraryOrNil:dartLibraryOrNil
334- (
flutter::RunConfiguration)runConfigurationForEntrypoint:(nullable NSString*)entrypointOrNil
335 libraryOrNil:(nullable NSString*)dartLibraryOrNil
337 (nullable NSArray<NSString*>*)entrypointArgs {
339 if (dartLibraryOrNil && entrypointOrNil) {
340 config.SetEntrypointAndLibrary(std::string([entrypointOrNil UTF8String]),
341 std::string([dartLibraryOrNil UTF8String]));
343 }
else if (entrypointOrNil) {
344 config.SetEntrypoint(std::string([entrypointOrNil UTF8String]));
347 if (entrypointArgs.count) {
348 std::vector<std::string> cppEntrypointArgs;
349 for (NSString* arg in entrypointArgs) {
350 cppEntrypointArgs.push_back(std::string([arg UTF8String]));
352 config.SetEntrypointArgs(std::move(cppEntrypointArgs));
358#pragma mark - Assets-related utilities
360+ (NSString*)flutterAssetsName:(NSBundle*)bundle {
367+ (NSString*)domainNetworkPolicy:(NSDictionary*)appTransportSecurity {
369 NSDictionary* exceptionDomains = appTransportSecurity[@"NSExceptionDomains"];
370 if (exceptionDomains == nil) {
373 NSMutableArray* networkConfigArray = [[NSMutableArray alloc] init];
374 for (NSString* domain in exceptionDomains) {
375 NSDictionary* domainConfiguration = exceptionDomains[domain];
377 bool includesSubDomains = [domainConfiguration[@"NSIncludesSubdomains"] boolValue];
378 bool allowsCleartextCommunication =
379 [domainConfiguration[@"NSExceptionAllowsInsecureHTTPLoads"] boolValue];
380 [networkConfigArray addObject:@[
381 domain, includesSubDomains ? @YES : @NO, allowsCleartextCommunication ? @YES : @NO
384 NSData* jsonData = [NSJSONSerialization dataWithJSONObject:networkConfigArray
387 return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
390+ (bool)allowsArbitraryLoads:(NSDictionary*)appTransportSecurity {
391 return [appTransportSecurity[@"NSAllowsArbitraryLoads"] boolValue];
394+ (NSString*)lookupKeyForAsset:(NSString*)asset {
395 return [
self lookupKeyForAsset:asset fromBundle:nil];
398+ (NSString*)lookupKeyForAsset:(NSString*)asset fromBundle:(nullable NSBundle*)bundle {
400 return [NSString stringWithFormat:@"%@/%@", flutterAssetsName, asset];
403+ (NSString*)lookupKeyForAsset:(NSString*)asset fromPackage:(NSString*)package {
404 return [
self lookupKeyForAsset:asset fromPackage:package fromBundle:nil];
407+ (NSString*)lookupKeyForAsset:(NSString*)asset
408 fromPackage:(NSString*)package
409 fromBundle:(nullable NSBundle*)bundle {
410 return [
self lookupKeyForAsset:[NSString stringWithFormat:@"packages/%@/%@", package, asset]
414+ (NSString*)defaultBundleIdentifier {
415 return @"io.flutter.flutter.app";