210- (int64_t)engineIdentifier {
211 return reinterpret_cast<int64_t
>((__bridge
void*)
self);
214- (instancetype)init {
215 return [
self initWithName:@"FlutterEngine" project:nil allowHeadlessExecution:YES];
218- (instancetype)initWithName:(NSString*)labelPrefix {
219 return [
self initWithName:labelPrefix project:nil allowHeadlessExecution:YES];
222- (instancetype)initWithName:(NSString*)labelPrefix project:(
FlutterDartProject*)project {
223 return [
self initWithName:labelPrefix project:project allowHeadlessExecution:YES];
226- (instancetype)initWithName:(NSString*)labelPrefix
228 allowHeadlessExecution:(
BOOL)allowHeadlessExecution {
229 return [
self initWithName:labelPrefix
231 allowHeadlessExecution:allowHeadlessExecution
232 restorationEnabled:NO];
235- (instancetype)initWithName:(NSString*)labelPrefix
237 allowHeadlessExecution:(
BOOL)allowHeadlessExecution
238 restorationEnabled:(
BOOL)restorationEnabled {
240 NSAssert(
self,
@"Super init cannot be nil");
241 NSAssert(labelPrefix,
@"labelPrefix is required");
245 _labelPrefix = [labelPrefix copy];
249 if (_enableEmbedderAPI) {
250 NSLog(
@"============== iOS: enable_embedder_api is on ==============");
257 @"Cannot create a FlutterEngine instance in debug mode without Flutter tooling or "
258 @"Xcode.\n\nTo launch in debug mode in iOS 14+, run flutter run from Flutter tools, run "
259 @"from an IDE with a Flutter IDE plugin or run the iOS project from Xcode.\nAlternatively "
260 @"profile and release mode apps can be launched from the home screen.");
264 _pluginPublications = [[NSMutableDictionary alloc] init];
265 _registrars = [[NSMutableDictionary alloc] init];
266 [
self recreatePlatformViewsController];
269 _connections = [[FlutterConnectionCollection alloc] init];
271 NSNotificationCenter*
center = [NSNotificationCenter defaultCenter];
272 [center addObserver:self
273 selector:@selector(onMemoryWarning:)
274 name:UIApplicationDidReceiveMemoryWarningNotification
277 [
self setUpLifecycleNotifications:center];
279 [center addObserver:self
280 selector:@selector(onLocaleUpdated:)
281 name:NSCurrentLocaleDidChangeNotification
290 NSAssert([[NSThread currentThread] isMainThread],
@"Must be called on the main thread.");
291 return (__bridge
FlutterEngine*)
reinterpret_cast<void*
>(identifier);
294- (void)setUpLifecycleNotifications:(NSNotificationCenter*)center {
296 [center addObserver:self
297 selector:@selector(sceneWillConnect:)
298 name:UISceneWillConnectNotification
301 [center addObserver:self
302 selector:@selector(sceneWillEnterForeground:)
303 name:UISceneWillEnterForegroundNotification
305 [center addObserver:self
306 selector:@selector(sceneDidEnterBackground:)
307 name:UISceneDidEnterBackgroundNotification
311 [center addObserver:self
312 selector:@selector(applicationWillEnterForeground:)
313 name:UIApplicationWillEnterForegroundNotification
315 [center addObserver:self
316 selector:@selector(applicationDidEnterBackground:)
317 name:UIApplicationDidEnterBackgroundNotification
321- (void)sceneWillConnect:(NSNotification*)notification API_AVAILABLE(ios(13.0)) {
322 UIScene* scene = notification.object;
332 if (sceneLifeCycleDelegate != nil) {
333 return [sceneLifeCycleDelegate engine:self receivedConnectNotificationFor:scene];
338- (void)recreatePlatformViewsController {
343- (
flutter::IOSRenderingAPI)platformViewsRenderingAPI {
350 [_pluginPublications enumerateKeysAndObjectsUsingBlock:^(id key, id object, BOOL* stop) {
351 if ([object respondsToSelector:@selector(detachFromEngineForRegistrar:)]) {
353 if ([registrar conformsToProtocol:@protocol(FlutterPluginRegistrar)]) {
354 [object detachFromEngineForRegistrar:((id<FlutterPluginRegistrar>)registrar)];
362 [_registrars enumerateKeysAndObjectsUsingBlock:^(id key, FlutterEngineBaseRegistrar* registrar,
364 registrar.flutterEngine = nil;
370 NSNotificationCenter*
center = [NSNotificationCenter defaultCenter];
371 if (_flutterViewControllerWillDeallocObserver) {
372 [center removeObserver:_flutterViewControllerWillDeallocObserver];
374 [center removeObserver:self];
382- (void)updateViewportMetrics:(
flutter::ViewportMetrics)viewportMetrics {
383 if (!
self.platformView) {
389- (void)dispatchPointerDataPacket:(
std::unique_ptr<
flutter::PointerDataPacket>)packet {
390 if (!
self.platformView) {
393 self.platformView->DispatchPointerDataPacket(std::move(packet));
396- (
BOOL)platformViewShouldAcceptTouchAtTouchBeganLocation:(
flutter::PointData)location
397 viewId:(uint64_t)viewId {
398 if (!
self.platformView) {
401 return self.platformView->HitTest(viewId,
location).has_platform_view;
404- (void)installFirstFrameCallback:(
void (^)(
void))block {
405 if (!
self.platformView) {
419 [strongSelf.platformTaskRunner postTask:^{
425- (void)enableSemantics:(
BOOL)enabled withFlags:(int64_t)flags {
426 if (!
self.platformView) {
429 self.platformView->SetSemanticsEnabled(enabled);
430 self.platformView->SetAccessibilityFeatures(flags);
433- (void)notifyViewCreated {
434 if (!
self.platformView) {
437 self.platformView->NotifyCreated();
440- (void)notifyViewDestroyed {
441 if (!
self.platformView) {
444 self.platformView->NotifyDestroyed();
447- (
flutter::PlatformViewIOS*)platformView {
468 userData:(
void*)userData API_AVAILABLE(ios(13.4)) {
469 if (@available(iOS 13.4, *)) {
473 if (!
self.platformView) {
481 switch (event.
type) {
493 key_data.
logical =
event.logical;
496 auto packet = std::make_unique<flutter::KeyDataPacket>(key_data,
character);
497 NSData*
message = [NSData dataWithBytes:packet->data().data() length:packet->data().size()];
499 auto response = ^(NSData* reply) {
503 BOOL handled = FALSE;
504 if (reply.length == 1 && *
reinterpret_cast<const uint8_t*
>(reply.bytes) == 1) {
510 [
self sendOnChannel:kFlutterKeyDataChannel message:message binaryReply:response];
513- (void)ensureSemanticsEnabled {
514 if (!
self.platformView) {
517 self.platformView->SetSemanticsEnabled(
true);
523 self.platformView->SetOwnerViewController(_viewController);
524 [
self maybeSetupPlatformViewChannels];
525 [
self updateDisplays];
530 self.flutterViewControllerWillDeallocObserver =
531 [[NSNotificationCenter defaultCenter] addObserverForName:FlutterViewControllerWillDealloc
532 object:viewController
533 queue:[NSOperationQueue mainQueue]
534 usingBlock:^(NSNotification* note) {
535 [weakSelf notifyViewControllerDeallocated];
538 self.flutterViewControllerWillDeallocObserver = nil;
539 [
self notifyLowMemory];
545 self.platformView->attachView();
548- (void)setFlutterViewControllerWillDeallocObserver:(
id<NSObject>)observer {
549 if (observer != _flutterViewControllerWillDeallocObserver) {
550 if (_flutterViewControllerWillDeallocObserver) {
551 [[NSNotificationCenter defaultCenter]
552 removeObserver:_flutterViewControllerWillDeallocObserver];
554 _flutterViewControllerWillDeallocObserver = observer;
558- (void)notifyViewControllerDeallocated {
559 [
self.lifecycleChannel sendMessage:@"AppLifecycleState.detached"];
560 self.textInputPlugin.viewController = nil;
561 if (!
self.allowHeadlessExecution) {
562 [
self destroyContext];
563 }
else if (
self.platformView) {
564 self.platformView->SetOwnerViewController({});
566 [
self.textInputPlugin resetViewResponder];
567 _viewController = nil;
570- (void)destroyContext {
571 [
self resetChannels];
572 self.isolateId = nil;
576 _platformViewsController = nil;
866static void SetEntryPoint(
flutter::Settings* settings, NSString* entrypoint, NSString* libraryURI) {
868 FML_DCHECK(entrypoint) <<
"Must specify entrypoint if specifying library";
871 }
else if (entrypoint) {
880- (
BOOL)createShell:(NSString*)entrypoint
881 libraryURI:(NSString*)libraryURI
882 initialRoute:(NSString*)initialRoute {
884 [FlutterLogger logWarning:@"This FlutterEngine was already invoked."];
888 self.initialRoute = initialRoute;
890 auto settings = [
self.dartProject settings];
891 if (initialRoute != nil) {
892 self.initialRoute = initialRoute;
893 }
else if (settings.
route.empty() ==
false) {
894 self.initialRoute = [NSString stringWithUTF8String:settings.route.c_str()];
897 auto platformData = [
self.dartProject defaultPlatformData];
899 SetEntryPoint(&settings, entrypoint, libraryURI);
901 NSString* threadLabel = [
FlutterEngine generateThreadLabel:self.labelPrefix];
902 _threadHost = std::make_shared<flutter::ThreadHost>();
903 *_threadHost = MakeThreadHost(threadLabel, settings);
910 return std::unique_ptr<flutter::PlatformViewIOS>();
912 [strongSelf recreatePlatformViewsController];
914 initWithTaskRunner:shell.GetTaskRunners().GetPlatformTaskRunner()];
915 return std::make_unique<flutter::PlatformViewIOS>(
916 shell, strongSelf->_renderingApi, strongSelf.platformViewsController,
917 shell.GetTaskRunners(), shell.GetConcurrentWorkerTaskRunner(),
918 shell.GetIsGpuDisabledSyncSwitch());
922 [](
flutter::Shell& shell) {
return std::make_unique<flutter::Rasterizer>(shell); };
929 ui_runner = _threadHost->ui_thread->GetTaskRunner();
933 _threadHost->raster_thread->GetTaskRunner(),
935 _threadHost->io_thread->GetTaskRunner()
939 self.isGpuDisabled =
self.viewController
940 ?
self.viewController.stateIsBackground
943 UIApplicationStateBackground;
950 on_create_platform_view,
951 on_create_rasterizer,
954 if (shell ==
nullptr) {
955 NSString* errorMessage = [NSString
956 stringWithFormat:@"Could not start a shell FlutterEngine with entrypoint: %@", entrypoint];
957 [FlutterLogger logError:errorMessage];
959 [
self setUpShell:std::move(shell)
960 withVMServicePublication:settings.enable_vm_service_publication];
962 [
self startProfiler];
969- (
BOOL)performImplicitEngineCallback {
971 if ([appDelegate conformsToProtocol:@protocol(FlutterImplicitEngineDelegate)]) {
972 id<FlutterImplicitEngineDelegate> provider = (id<FlutterImplicitEngineDelegate>)appDelegate;
974 initWithEngine:self]];
980- (void)updateDisplays {
985 auto vsync_waiter =
_shell->GetVsyncWaiter().lock();
986 auto vsync_waiter_ios = std::static_pointer_cast<flutter::VsyncWaiterIOS>(vsync_waiter);
987 std::vector<std::unique_ptr<flutter::Display>>
displays;
988 auto screen_size = UIScreen.mainScreen.nativeBounds.size;
989 auto scale = UIScreen.mainScreen.scale;
990 displays.push_back(std::make_unique<flutter::VariableRefreshRateDisplay>(
991 0, vsync_waiter_ios, screen_size.width, screen_size.height, scale));
996 return [
self runWithEntrypoint:FlutterDefaultDartEntrypoint
998 initialRoute:FlutterDefaultInitialRoute];
1001- (
BOOL)runWithEntrypoint:(NSString*)entrypoint libraryURI:(NSString*)libraryURI {
1002 return [
self runWithEntrypoint:entrypoint
1003 libraryURI:libraryURI
1004 initialRoute:FlutterDefaultInitialRoute];
1007- (
BOOL)runWithEntrypoint:(NSString*)entrypoint {
1008 return [
self runWithEntrypoint:entrypoint libraryURI:nil initialRoute:FlutterDefaultInitialRoute];
1011- (
BOOL)runWithEntrypoint:(NSString*)entrypoint initialRoute:(NSString*)initialRoute {
1012 return [
self runWithEntrypoint:entrypoint libraryURI:nil initialRoute:initialRoute];
1015- (
BOOL)runWithEntrypoint:(NSString*)entrypoint
1016 libraryURI:(NSString*)libraryURI
1017 initialRoute:(NSString*)initialRoute {
1018 return [
self runWithEntrypoint:entrypoint
1019 libraryURI:libraryURI
1020 initialRoute:initialRoute
1021 entrypointArgs:nil];
1024- (
BOOL)runWithEntrypoint:(NSString*)entrypoint
1025 libraryURI:(NSString*)libraryURI
1026 initialRoute:(NSString*)initialRoute
1027 entrypointArgs:(NSArray<NSString*>*)entrypointArgs {
1028 if ([
self createShell:entrypoint libraryURI:libraryURI initialRoute:initialRoute]) {
1029 [
self launchEngine:entrypoint libraryURI:libraryURI entrypointArgs:entrypointArgs];
1032 return _shell !=
nullptr;
1035- (void)notifyLowMemory {
1037 _shell->NotifyLowMemoryWarning();
1039 [
self.systemChannel sendMessage:@{@"type" : @"memoryPressure"}];
1042#pragma mark - Text input delegate
1045 updateEditingClient:(
int)client
1046 withState:(NSDictionary*)state {
1047 [
self.textInputChannel invokeMethod:@"TextInputClient.updateEditingState"
1048 arguments:@[ @(client), state ]];
1052 updateEditingClient:(
int)client
1053 withState:(NSDictionary*)state
1054 withTag:(NSString*)tag {
1055 [
self.textInputChannel invokeMethod:@"TextInputClient.updateEditingStateWithTag"
1056 arguments:@[ @(client), @{tag : state} ]];
1060 updateEditingClient:(
int)client
1061 withDelta:(NSDictionary*)delta {
1062 [
self.textInputChannel invokeMethod:@"TextInputClient.updateEditingStateWithDeltas"
1063 arguments:@[ @(client), delta ]];
1067 updateFloatingCursor:(FlutterFloatingCursorDragState)state
1068 withClient:(
int)client
1069 withPosition:(NSDictionary*)position {
1070 NSString* stateString;
1072 case FlutterFloatingCursorDragStateStart:
1073 stateString =
@"FloatingCursorDragState.start";
1075 case FlutterFloatingCursorDragStateUpdate:
1076 stateString =
@"FloatingCursorDragState.update";
1078 case FlutterFloatingCursorDragStateEnd:
1079 stateString =
@"FloatingCursorDragState.end";
1082 [
self.textInputChannel invokeMethod:@"TextInputClient.updateFloatingCursor"
1083 arguments:@[ @(client), stateString, position ]];
1087 performAction:(FlutterTextInputAction)action
1088 withClient:(
int)client {
1089 NSString* actionString;
1091 case FlutterTextInputActionUnspecified:
1096 actionString =
@"TextInputAction.unspecified";
1098 case FlutterTextInputActionDone:
1099 actionString =
@"TextInputAction.done";
1101 case FlutterTextInputActionGo:
1102 actionString =
@"TextInputAction.go";
1104 case FlutterTextInputActionSend:
1105 actionString =
@"TextInputAction.send";
1107 case FlutterTextInputActionSearch:
1108 actionString =
@"TextInputAction.search";
1110 case FlutterTextInputActionNext:
1111 actionString =
@"TextInputAction.next";
1113 case FlutterTextInputActionContinue:
1114 actionString =
@"TextInputAction.continueAction";
1116 case FlutterTextInputActionJoin:
1117 actionString =
@"TextInputAction.join";
1119 case FlutterTextInputActionRoute:
1120 actionString =
@"TextInputAction.route";
1122 case FlutterTextInputActionEmergencyCall:
1123 actionString =
@"TextInputAction.emergencyCall";
1125 case FlutterTextInputActionNewline:
1126 actionString =
@"TextInputAction.newline";
1129 [
self.textInputChannel invokeMethod:@"TextInputClient.performAction"
1130 arguments:@[ @(client), actionString ]];
1134 showAutocorrectionPromptRectForStart:(NSUInteger)start
1136 withClient:(
int)client {
1137 [
self.textInputChannel invokeMethod:@"TextInputClient.showAutocorrectionPromptRect"
1138 arguments:@[ @(client), @(start), @(end) ]];
1142 willDismissEditMenuWithTextInputClient:(
int)client {
1143 [
self.platformChannel invokeMethod:@"ContextMenu.onDismissSystemContextMenu"
1144 arguments:@[ @(client) ]];
1148 shareSelectedText:(NSString*)selectedText {
1149 [
self.platformPlugin showShareViewController:selectedText];
1153 searchWebWithSelectedText:(NSString*)selectedText {
1154 [
self.platformPlugin searchWeb:selectedText];
1158 lookUpSelectedText:(NSString*)selectedText {
1159 [
self.platformPlugin showLookUpViewController:selectedText];
1163 performContextMenuCustomActionWithActionID:(NSString*)actionID
1164 textInputClient:(
int)client {
1165 [
self.platformChannel invokeMethod:@"ContextMenu.onPerformCustomAction"
1166 arguments:@[ @(client), actionID ]];
1169#pragma mark - FlutterViewEngineDelegate
1175 [
self.textInputChannel invokeMethod:@"TextInputClient.showToolbar" arguments:@[ @(client) ]];
1179 focusElement:(UIScribbleElementIdentifier)elementIdentifier
1180 atPoint:(CGPoint)referencePoint
1185 [
self.textInputChannel
1186 invokeMethod:@"TextInputClient.focusElement"
1187 arguments:@[ elementIdentifier, @(referencePoint.x), @(referencePoint.y) ]
1192 requestElementsInRect:(CGRect)rect
1197 [
self.textInputChannel
1198 invokeMethod:@"TextInputClient.requestElementsInRect"
1199 arguments:@[ @(rect.origin.x), @(rect.origin.y), @(rect.size.width), @(rect.size.height) ]
1207 [
self.textInputChannel invokeMethod:@"TextInputClient.scribbleInteractionBegan" arguments:nil];
1214 [
self.textInputChannel invokeMethod:@"TextInputClient.scribbleInteractionFinished" arguments:nil];
1218 insertTextPlaceholderWithSize:(CGSize)size
1219 withClient:(
int)client {
1223 [
self.textInputChannel invokeMethod:@"TextInputClient.insertTextPlaceholder"
1224 arguments:@[ @(client), @(size.width), @(size.height) ]];
1228 removeTextPlaceholder:(
int)client {
1232 [
self.textInputChannel invokeMethod:@"TextInputClient.removeTextPlaceholder"
1233 arguments:@[ @(client) ]];
1237 didResignFirstResponderWithTextInputClient:(
int)client {
1241 [
self.textInputChannel invokeMethod:@"TextInputClient.onConnectionClosed"
1242 arguments:@[ @(client) ]];
1263 dispatch_async(dispatch_get_main_queue(), ^(
void) {
1264 long platform_view_id = [
self.platformViewsController firstResponderPlatformViewId];
1265 if (platform_view_id == -1) {
1269 [
self.platformViewsChannel invokeMethod:@"viewFocused" arguments:@(platform_view_id)];
1273#pragma mark - Undo Manager Delegate
1275- (void)handleUndoWithDirection:(FlutterUndoRedoDirection)direction {
1276 NSString*
action = (direction == FlutterUndoRedoDirectionUndo) ?
@"undo" :
@"redo";
1277 [
self.undoManagerChannel invokeMethod:@"UndoManagerClient.handleUndo" arguments:@[ action ]];
1280- (UIView<UITextInput>*)activeTextInputView {
1281 return [[
self textInputPlugin] textInputView];
1284- (NSUndoManager*)undoManager {
1285 return self.viewController.undoManager;
1288#pragma mark - Screenshot Delegate
1290- (
flutter::Rasterizer::Screenshot)takeScreenshot:(
flutter::Rasterizer::ScreenshotType)type
1291 asBase64Encoded:(
BOOL)base64Encode {
1293 return _shell->Screenshot(
type, base64Encode);
1296- (void)flutterViewAccessibilityDidCall {
1297 if (
self.viewController.view.accessibilityElements == nil) {
1298 [
self ensureSemanticsEnabled];
1302- (NSObject<FlutterBinaryMessenger>*)binaryMessenger {
1306- (NSObject<FlutterTextureRegistry>*)textureRegistry {
1320#pragma mark - FlutterBinaryMessenger
1322- (void)sendOnChannel:(NSString*)channel message:(NSData*)message {
1323 [
self sendOnChannel:channel message:message binaryReply:nil];
1326- (void)sendOnChannel:(NSString*)channel
1327 message:(NSData*)message
1331 @"Sending a message before the FlutterEngine has been run.");
1338 _shell->GetTaskRunners().GetPlatformTaskRunner());
1339 std::unique_ptr<flutter::PlatformMessage> platformMessage =
1340 (
message == nil) ? std::make_unique<flutter::PlatformMessage>(
channel.UTF8String, response)
1341 : std::make_unique<flutter::PlatformMessage>(
1344 _shell->GetPlatformView()->DispatchPlatformMessage(std::move(platformMessage));
1349- (NSObject<FlutterTaskQueue>*)makeBackgroundTaskQueue {
1354 binaryMessageHandler:
1356 return [
self setMessageHandlerOnChannel:channel binaryMessageHandler:handler taskQueue:nil];
1360 setMessageHandlerOnChannel:(NSString*)channel
1362 taskQueue:(NSObject<FlutterTaskQueue>* _Nullable)taskQueue {
1365 self.platformView->GetPlatformMessageHandlerIos()->SetMessageHandler(
channel.UTF8String,
1367 return [
self.connections acquireConnectionForChannel:channel];
1369 NSAssert(!
handler,
@"Setting a message handler before the FlutterEngine has been run.");
1371 return [FlutterConnectionCollection makeErrorConnectionWithErrorCode:-1L];
1377 NSString*
channel = [
self.connections cleanupConnectionWithID:connection];
1379 self.platformView->GetPlatformMessageHandlerIos()->SetMessageHandler(
channel.UTF8String, nil,
1385#pragma mark - FlutterTextureRegistry
1389 int64_t textureId =
self.nextTextureId++;
1390 self.platformView->RegisterExternalTexture(textureId,
texture);
1394- (void)unregisterTexture:(int64_t)textureId {
1395 _shell->GetPlatformView()->UnregisterTexture(textureId);
1398- (void)textureFrameAvailable:(int64_t)textureId {
1399 _shell->GetPlatformView()->MarkTextureFrameAvailable(textureId);
1402- (NSString*)lookupKeyForAsset:(NSString*)asset {
1406- (NSString*)lookupKeyForAsset:(NSString*)asset fromPackage:(NSString*)package {
1410- (
id<FlutterPluginRegistry>)pluginRegistry {
1414#pragma mark - FlutterPluginRegistry
1416- (NSObject<FlutterPluginRegistrar>*)registrarForPlugin:(NSString*)pluginKey {
1417 NSAssert(
self.pluginPublications[pluginKey] == nil,
@"Duplicate plugin key: %@", pluginKey);
1418 self.pluginPublications[pluginKey] = [NSNull null];
1420 flutterEngine:self];
1421 self.registrars[pluginKey] = result;
1425- (NSObject<FlutterApplicationRegistrar>*)registrarForApplication:(NSString*)key {
1426 NSAssert(
self.pluginPublications[
key] == nil,
@"Duplicate key: %@",
key);
1427 self.pluginPublications[key] = [NSNull null];
1430 self.registrars[key] = result;
1434- (
BOOL)hasPlugin:(NSString*)pluginKey {
1435 return _pluginPublications[pluginKey] != nil;
1438- (NSObject*)valuePublishedByPlugin:(NSString*)pluginKey {
1439 return _pluginPublications[pluginKey];
1442- (void)addSceneLifeCycleDelegate:(NSObject<FlutterSceneLifeCycleDelegate>*)delegate {
1443 [
self.sceneLifeCycleDelegate addDelegate:delegate];
1446#pragma mark - Notifications
1448- (void)sceneWillEnterForeground:(NSNotification*)notification API_AVAILABLE(ios(13.0)) {
1449 [
self flutterWillEnterForeground:notification];
1452- (void)sceneDidEnterBackground:(NSNotification*)notification API_AVAILABLE(ios(13.0)) {
1453 [
self flutterDidEnterBackground:notification];
1456- (void)applicationWillEnterForeground:(NSNotification*)notification {
1457 [
self flutterWillEnterForeground:notification];
1460- (void)applicationDidEnterBackground:(NSNotification*)notification {
1461 [
self flutterDidEnterBackground:notification];
1464- (void)flutterWillEnterForeground:(NSNotification*)notification {
1465 [
self setIsGpuDisabled:NO];
1468- (void)flutterDidEnterBackground:(NSNotification*)notification {
1469 [
self setIsGpuDisabled:YES];
1470 [
self notifyLowMemory];
1473- (void)onMemoryWarning:(NSNotification*)notification {
1474 [
self notifyLowMemory];
1477- (void)setIsGpuDisabled:(
BOOL)value {
1482 _isGpuDisabled =
value;
1485#pragma mark - Locale updates
1487- (void)onLocaleUpdated:(NSNotification*)notification {
1489 NSMutableArray<NSString*>* localeData = [[NSMutableArray alloc] init];
1490 NSArray<NSString*>* preferredLocales = [NSLocale preferredLanguages];
1491 for (NSString* localeID in preferredLocales) {
1492 NSLocale* locale = [[NSLocale alloc] initWithLocaleIdentifier:localeID];
1493 NSString* languageCode = [locale objectForKey:NSLocaleLanguageCode];
1494 NSString* countryCode = [locale objectForKey:NSLocaleCountryCode];
1495 NSString* scriptCode = [locale objectForKey:NSLocaleScriptCode];
1496 NSString* variantCode = [locale objectForKey:NSLocaleVariantCode];
1497 if (!languageCode) {
1500 [localeData addObject:languageCode];
1501 [localeData addObject:(countryCode ? countryCode : @"")];
1502 [localeData addObject:(scriptCode ? scriptCode : @"")];
1503 [localeData addObject:(variantCode ? variantCode : @"")];
1505 if (localeData.count == 0) {
1508 [
self.localizationChannel invokeMethod:@"setLocale" arguments:localeData];
1511- (void)onStatusBarTap {
1515 [
self.statusBarChannel invokeMethod:@"handleScrollToTop" arguments:nil];
1518- (void)waitForFirstFrameSync:(NSTimeInterval)timeout
1519 callback:(NS_NOESCAPE
void (^_Nonnull)(
BOOL didTimeout))callback {
1525- (void)waitForFirstFrame:(NSTimeInterval)timeout
1526 callback:(
void (^_Nonnull)(
BOOL didTimeout))callback {
1527 dispatch_queue_t
queue = dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0);
1528 dispatch_group_t group = dispatch_group_create();
1531 __block
BOOL didTimeout = NO;
1532 dispatch_group_async(group,
queue, ^{
1544 dispatch_group_notify(group, dispatch_get_main_queue(), ^{
1563 libraryURI:( NSString*)libraryURI
1564 initialRoute:( NSString*)initialRoute
1565 entrypointArgs:( NSArray<NSString*>*)entrypointArgs {
1566 NSAssert(
_shell,
@"Spawning from an engine without a shell (possibly not run).");
1568 project:self.dartProject
1569 allowHeadlessExecution:self.allowHeadlessExecution];
1571 [
self.dartProject runConfigurationForEntrypoint:entrypoint
1572 libraryOrNil:libraryURI
1573 entrypointArgs:entrypointArgs];
1575 configuration.
SetEngineId(result.engineIdentifier);
1582 std::shared_ptr<flutter::IOSContext> context = ios_platform_view->
GetIosContext();
1589 [result recreatePlatformViewsController];
1591 initWithTaskRunner:shell.GetTaskRunners().GetPlatformTaskRunner()];
1592 return std::make_unique<flutter::PlatformViewIOS>(
1593 shell, context, result.platformViewsController, shell.GetTaskRunners());
1597 [](
flutter::Shell& shell) {
return std::make_unique<flutter::Rasterizer>(shell); };
1599 std::string cppInitialRoute;
1601 cppInitialRoute = [initialRoute UTF8String];
1604 std::unique_ptr<flutter::Shell> shell =
_shell->Spawn(
1605 std::move(configuration), cppInitialRoute, on_create_platform_view, on_create_rasterizer);
1607 result->_threadHost = _threadHost;
1609 result->_isGpuDisabled = _isGpuDisabled;
1610 [result setUpShell:std::move(shell) withVMServicePublication:NO];
1614- (const
flutter::ThreadHost&)threadHost {
1615 return *_threadHost;
1619 return self.dartProject;
1622- (void)sendDeepLinkToFramework:(NSURL*)url completionHandler:(
void (^)(
BOOL success))completion {
1624 [
self waitForFirstFrame:3.0
1625 callback:^(BOOL didTimeout) {
1628 logError:@"Timeout waiting for first frame when launching a URL."];
1632 [weakSelf.navigationChannel
1633 invokeMethod:@"pushRouteInformation"
1635 @"location" : url.absoluteString ?: [NSNull null],
1637 result:^(id _Nullable result) {
1639 [result isKindOfClass:[NSNumber class]] && [result boolValue];
1643 logError:@"Failed to handle route information in Flutter."];
1645 completion(success);
1655- (instancetype)initWithKey:(NSString*)key flutterEngine:(
FlutterEngine*)flutterEngine {
1656 self = [
super init];
1657 NSAssert(
self,
@"Super init cannot be nil");