67 bool hasExplicitBundle = bundle != nil;
78 settings.task_observer_remove = [](intptr_t
key) {
82 settings.log_message_callback = [](
const std::string& tag,
const std::string&
message) {
85 std::stringstream stream;
87 stream << tag <<
": ";
90 std::string log = stream.str();
91 syslog(LOG_ALERT,
"%.*s", (
int)log.size(), log.c_str());
94 settings.enable_platform_isolates =
true;
100 if (settings.icu_data_path.empty()) {
101 NSString* icuDataPath = [engineBundle pathForResource:
@"icudtl" ofType:
@"dat"];
102 if (icuDataPath.length > 0) {
103 settings.icu_data_path = icuDataPath.UTF8String;
108 if (hasExplicitBundle) {
109 NSString* executablePath = bundle.executablePath;
110 if ([[NSFileManager defaultManager] fileExistsAtPath:executablePath]) {
111 settings.application_library_path.push_back(executablePath.UTF8String);
116 if (settings.application_library_path.empty()) {
117 NSString* libraryName = [mainBundle objectForInfoDictionaryKey:
@"FLTLibraryPath"];
118 NSString* libraryPath = [mainBundle pathForResource:libraryName ofType:
@""];
119 if (libraryPath.length > 0) {
120 NSString* executablePath = [NSBundle bundleWithPath:libraryPath].executablePath;
121 if (executablePath.length > 0) {
122 settings.application_library_path.push_back(executablePath.UTF8String);
129 if (settings.application_library_path.empty()) {
130 NSString* applicationFrameworkPath = [mainBundle pathForResource:
@"Frameworks/App.framework"
132 if (applicationFrameworkPath.length > 0) {
133 NSString* executablePath =
134 [NSBundle bundleWithPath:applicationFrameworkPath].executablePath;
135 if (executablePath.length > 0) {
136 settings.application_library_path.push_back(executablePath.UTF8String);
143 if (settings.assets_path.empty()) {
146 if (assetsPath.length == 0) {
147 NSLog(
@"Failed to find assets path for \"%@\
"", bundle);
149 settings.assets_path = assetsPath.UTF8String;
155 NSURL* applicationKernelSnapshotURL =
157 relativeToURL:[NSURL fileURLWithPath:assetsPath]];
159 if ([applicationKernelSnapshotURL checkResourceIsReachableAndReturnError:&
error]) {
160 settings.application_kernel_asset = applicationKernelSnapshotURL.path.UTF8String;
162 NSLog(
@"Failed to find snapshot at %@: %@", applicationKernelSnapshotURL.path,
error);
171 settings.may_insecurely_connect_to_all_domains =
true;
172 settings.domain_network_policy =
"";
175#if TARGET_OS_SIMULATOR
178 settings.enable_wide_gamut =
false;
182 NSNumber* nsEnableWideGamut = [mainBundle objectForInfoDictionaryKey:
@"FLTEnableWideGamut"];
183 BOOL enableWideGamut =
185 settings.enable_wide_gamut = enableWideGamut;
192 if (!command_line.HasOption(
"enable-impeller")) {
194 NSNumber* enableImpeller = [bundle objectForInfoDictionaryKey:
@"FLTEnableImpeller"];
195 if (enableImpeller == nil) {
197 enableImpeller = [mainBundle objectForInfoDictionaryKey:
@"FLTEnableImpeller"];
200 if (enableImpeller != nil) {
201 settings.enable_impeller = enableImpeller.boolValue;
205 settings.warn_on_impeller_opt_out =
true;
207 NSNumber* enableTraceSystrace = [mainBundle objectForInfoDictionaryKey:
@"FLTTraceSystrace"];
209 if (enableTraceSystrace != nil) {
210 settings.trace_systrace = enableTraceSystrace.boolValue;
213 NSNumber* enableDartAsserts = [mainBundle objectForInfoDictionaryKey:
@"FLTEnableDartAsserts"];
214 if (enableDartAsserts != nil) {
215 settings.dart_flags.push_back(
"--enable-asserts");
218 NSNumber* enableDartProfiling = [mainBundle objectForInfoDictionaryKey:
@"FLTEnableDartProfiling"];
220 if (enableDartProfiling != nil) {
221 settings.enable_dart_profiling = enableDartProfiling.boolValue;
225 NSNumber* leakDartVM = [mainBundle objectForInfoDictionaryKey:
@"FLTLeakDartVM"];
227 if (leakDartVM != nil) {
228 settings.leak_vm = leakDartVM.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];
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 objectForKey:@"NSExceptionDomains"];
373 if (exceptionDomains == nil) {
376 NSMutableArray* networkConfigArray = [[[NSMutableArray alloc] init] autorelease];
377 for (NSString* domain in exceptionDomains) {
378 NSDictionary* domainConfiguration = [exceptionDomains objectForKey:domain];
380 bool includesSubDomains =
381 [[domainConfiguration objectForKey:@"NSIncludesSubdomains"] boolValue];
382 bool allowsCleartextCommunication =
383 [[domainConfiguration objectForKey:@"NSExceptionAllowsInsecureHTTPLoads"] boolValue];
384 [networkConfigArray addObject:@[
385 domain, includesSubDomains ? @YES : @NO, allowsCleartextCommunication ? @YES : @NO
388 NSData* jsonData = [NSJSONSerialization dataWithJSONObject:networkConfigArray
391 return [[[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding] autorelease];
394+ (bool)allowsArbitraryLoads:(NSDictionary*)appTransportSecurity {
395 return [[appTransportSecurity objectForKey:@"NSAllowsArbitraryLoads"] boolValue];