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 if (
self.viewController && ![
self.viewController shouldHandleSceneNotification:notification]) {
325 UIScene* scene = notification.object;
335 if (sceneLifeCycleDelegate != nil) {
336 return [sceneLifeCycleDelegate engine:self receivedConnectNotificationFor:scene];
341- (void)recreatePlatformViewsController {
346- (
flutter::IOSRenderingAPI)platformViewsRenderingAPI {
353 [_pluginPublications enumerateKeysAndObjectsUsingBlock:^(id key, id object, BOOL* stop) {
354 if ([object respondsToSelector:@selector(detachFromEngineForRegistrar:)]) {
356 if ([registrar conformsToProtocol:@protocol(FlutterPluginRegistrar)]) {
357 [object detachFromEngineForRegistrar:((id<FlutterPluginRegistrar>)registrar)];
365 [_registrars enumerateKeysAndObjectsUsingBlock:^(id key, FlutterEngineBaseRegistrar* registrar,
367 registrar.flutterEngine = nil;
373 NSNotificationCenter*
center = [NSNotificationCenter defaultCenter];
374 if (_flutterViewControllerWillDeallocObserver) {
375 [center removeObserver:_flutterViewControllerWillDeallocObserver];
377 [center removeObserver:self];
385- (void)updateViewportMetrics:(
flutter::ViewportMetrics)viewportMetrics {
386 if (!
self.platformView) {
392- (void)dispatchPointerDataPacket:(
std::unique_ptr<
flutter::PointerDataPacket>)packet {
393 if (!
self.platformView) {
396 self.platformView->DispatchPointerDataPacket(std::move(packet));
399- (
BOOL)platformViewShouldAcceptTouchAtTouchBeganLocation:(
flutter::PointData)location
400 viewId:(uint64_t)viewId {
401 if (!
self.platformView) {
404 return self.platformView->HitTest(viewId,
location).has_platform_view;
407- (void)installFirstFrameCallback:(
void (^)(
void))block {
408 if (!
self.platformView) {
422 [strongSelf.platformTaskRunner postTask:^{
428- (void)enableSemantics:(
BOOL)enabled withFlags:(int64_t)flags {
429 if (!
self.platformView) {
432 self.platformView->SetSemanticsEnabled(enabled);
433 self.platformView->SetAccessibilityFeatures(flags);
436- (void)notifyViewCreated {
437 if (!
self.platformView) {
440 self.platformView->NotifyCreated();
443- (void)notifyViewDestroyed {
444 if (!
self.platformView) {
447 self.platformView->NotifyDestroyed();
450- (
flutter::PlatformViewIOS*)platformView {
471 userData:(
void*)userData API_AVAILABLE(ios(13.4)) {
472 if (@available(iOS 13.4, *)) {
476 if (!
self.platformView) {
484 switch (event.
type) {
496 key_data.
logical =
event.logical;
499 auto packet = std::make_unique<flutter::KeyDataPacket>(key_data,
character);
500 NSData*
message = [NSData dataWithBytes:packet->data().data() length:packet->data().size()];
502 auto response = ^(NSData* reply) {
506 BOOL handled = FALSE;
507 if (reply.length == 1 && *
reinterpret_cast<const uint8_t*
>(reply.bytes) == 1) {
513 [
self sendOnChannel:kFlutterKeyDataChannel message:message binaryReply:response];
516- (void)ensureSemanticsEnabled {
517 if (!
self.platformView) {
520 self.platformView->SetSemanticsEnabled(
true);
526 self.platformView->SetOwnerViewController(_viewController);
527 [
self maybeSetupPlatformViewChannels];
528 [
self updateDisplays];
533 self.flutterViewControllerWillDeallocObserver =
534 [[NSNotificationCenter defaultCenter] addObserverForName:FlutterViewControllerWillDealloc
535 object:viewController
536 queue:[NSOperationQueue mainQueue]
537 usingBlock:^(NSNotification* note) {
538 [weakSelf notifyViewControllerDeallocated];
541 self.flutterViewControllerWillDeallocObserver = nil;
542 [
self notifyLowMemory];
548 self.platformView->attachView();
551- (void)setFlutterViewControllerWillDeallocObserver:(
id<NSObject>)observer {
552 if (observer != _flutterViewControllerWillDeallocObserver) {
553 if (_flutterViewControllerWillDeallocObserver) {
554 [[NSNotificationCenter defaultCenter]
555 removeObserver:_flutterViewControllerWillDeallocObserver];
557 _flutterViewControllerWillDeallocObserver = observer;
561- (void)notifyViewControllerDeallocated {
562 [
self.lifecycleChannel sendMessage:@"AppLifecycleState.detached"];
563 self.textInputPlugin.viewController = nil;
564 if (!
self.allowHeadlessExecution) {
565 [
self destroyContext];
566 }
else if (
self.platformView) {
567 self.platformView->SetOwnerViewController({});
569 [
self.textInputPlugin resetViewResponder];
570 _viewController = nil;
573- (void)destroyContext {
574 [
self resetChannels];
575 self.isolateId = nil;
579 _platformViewsController = nil;
869static void SetEntryPoint(
flutter::Settings* settings, NSString* entrypoint, NSString* libraryURI) {
871 FML_DCHECK(entrypoint) <<
"Must specify entrypoint if specifying library";
874 }
else if (entrypoint) {
883- (
BOOL)createShell:(NSString*)entrypoint
884 libraryURI:(NSString*)libraryURI
885 initialRoute:(NSString*)initialRoute {
887 [FlutterLogger logWarning:@"This FlutterEngine was already invoked."];
891 self.initialRoute = initialRoute;
893 auto settings = [
self.dartProject settings];
894 if (initialRoute != nil) {
895 self.initialRoute = initialRoute;
896 }
else if (settings.
route.empty() ==
false) {
897 self.initialRoute = [NSString stringWithUTF8String:settings.route.c_str()];
900 auto platformData = [
self.dartProject defaultPlatformData];
902 SetEntryPoint(&settings, entrypoint, libraryURI);
904 NSString* threadLabel = [
FlutterEngine generateThreadLabel:self.labelPrefix];
905 _threadHost = std::make_shared<flutter::ThreadHost>();
906 *_threadHost = MakeThreadHost(threadLabel, settings);
913 return std::unique_ptr<flutter::PlatformViewIOS>();
915 [strongSelf recreatePlatformViewsController];
917 initWithTaskRunner:shell.GetTaskRunners().GetPlatformTaskRunner()];
918 return std::make_unique<flutter::PlatformViewIOS>(
919 shell, strongSelf->_renderingApi, strongSelf.platformViewsController,
920 shell.GetTaskRunners(), shell.GetIsGpuDisabledSyncSwitch());
924 [](
flutter::Shell& shell) {
return std::make_unique<flutter::Rasterizer>(shell); };
931 ui_runner = _threadHost->ui_thread->GetTaskRunner();
935 _threadHost->raster_thread->GetTaskRunner(),
937 _threadHost->io_thread->GetTaskRunner()
941 self.isGpuDisabled =
self.viewController
942 ?
self.viewController.stateIsBackground
945 UIApplicationStateBackground;
952 on_create_platform_view,
953 on_create_rasterizer,
956 if (shell ==
nullptr) {
957 NSString* errorMessage = [NSString
958 stringWithFormat:@"Could not start a shell FlutterEngine with entrypoint: %@", entrypoint];
959 [FlutterLogger logError:errorMessage];
961 [
self setUpShell:std::move(shell)
962 withVMServicePublication:settings.enable_vm_service_publication];
964 [
self startProfiler];
971- (
BOOL)performImplicitEngineCallback {
973 if ([appDelegate conformsToProtocol:@protocol(FlutterImplicitEngineDelegate)]) {
974 id<FlutterImplicitEngineDelegate> provider = (id<FlutterImplicitEngineDelegate>)appDelegate;
976 initWithEngine:self]];
982- (void)updateDisplays {
987 auto vsync_waiter =
_shell->GetVsyncWaiter().lock();
988 auto vsync_waiter_ios = std::static_pointer_cast<flutter::VsyncWaiterIOS>(vsync_waiter);
989 std::vector<std::unique_ptr<flutter::Display>>
displays;
990 auto screen_size = UIScreen.mainScreen.nativeBounds.size;
991 auto scale = UIScreen.mainScreen.scale;
992 displays.push_back(std::make_unique<flutter::VariableRefreshRateDisplay>(
993 0, vsync_waiter_ios, screen_size.width, screen_size.height, scale));
998 return [
self runWithEntrypoint:FlutterDefaultDartEntrypoint
1000 initialRoute:FlutterDefaultInitialRoute];
1003- (
BOOL)runWithEntrypoint:(NSString*)entrypoint libraryURI:(NSString*)libraryURI {
1004 return [
self runWithEntrypoint:entrypoint
1005 libraryURI:libraryURI
1006 initialRoute:FlutterDefaultInitialRoute];
1009- (
BOOL)runWithEntrypoint:(NSString*)entrypoint {
1010 return [
self runWithEntrypoint:entrypoint libraryURI:nil initialRoute:FlutterDefaultInitialRoute];
1013- (
BOOL)runWithEntrypoint:(NSString*)entrypoint initialRoute:(NSString*)initialRoute {
1014 return [
self runWithEntrypoint:entrypoint libraryURI:nil initialRoute:initialRoute];
1017- (
BOOL)runWithEntrypoint:(NSString*)entrypoint
1018 libraryURI:(NSString*)libraryURI
1019 initialRoute:(NSString*)initialRoute {
1020 return [
self runWithEntrypoint:entrypoint
1021 libraryURI:libraryURI
1022 initialRoute:initialRoute
1023 entrypointArgs:nil];
1026- (
BOOL)runWithEntrypoint:(NSString*)entrypoint
1027 libraryURI:(NSString*)libraryURI
1028 initialRoute:(NSString*)initialRoute
1029 entrypointArgs:(NSArray<NSString*>*)entrypointArgs {
1030 if ([
self createShell:entrypoint libraryURI:libraryURI initialRoute:initialRoute]) {
1031 [
self launchEngine:entrypoint libraryURI:libraryURI entrypointArgs:entrypointArgs];
1034 return _shell !=
nullptr;
1037- (void)notifyLowMemory {
1039 _shell->NotifyLowMemoryWarning();
1041 [
self.systemChannel sendMessage:@{@"type" : @"memoryPressure"}];
1044#pragma mark - Text input delegate
1047 updateEditingClient:(
int)client
1048 withState:(NSDictionary*)state {
1049 [
self.textInputChannel invokeMethod:@"TextInputClient.updateEditingState"
1050 arguments:@[ @(client), state ]];
1054 updateEditingClient:(
int)client
1055 withState:(NSDictionary*)state
1056 withTag:(NSString*)tag {
1057 [
self.textInputChannel invokeMethod:@"TextInputClient.updateEditingStateWithTag"
1058 arguments:@[ @(client), @{tag : state} ]];
1062 updateEditingClient:(
int)client
1063 withDelta:(NSDictionary*)delta {
1064 [
self.textInputChannel invokeMethod:@"TextInputClient.updateEditingStateWithDeltas"
1065 arguments:@[ @(client), delta ]];
1069 updateFloatingCursor:(FlutterFloatingCursorDragState)state
1070 withClient:(
int)client
1071 withPosition:(NSDictionary*)position {
1072 NSString* stateString;
1074 case FlutterFloatingCursorDragStateStart:
1075 stateString =
@"FloatingCursorDragState.start";
1077 case FlutterFloatingCursorDragStateUpdate:
1078 stateString =
@"FloatingCursorDragState.update";
1080 case FlutterFloatingCursorDragStateEnd:
1081 stateString =
@"FloatingCursorDragState.end";
1084 [
self.textInputChannel invokeMethod:@"TextInputClient.updateFloatingCursor"
1085 arguments:@[ @(client), stateString, position ]];
1089 performAction:(FlutterTextInputAction)action
1090 withClient:(
int)client {
1091 NSString* actionString;
1093 case FlutterTextInputActionUnspecified:
1098 actionString =
@"TextInputAction.unspecified";
1100 case FlutterTextInputActionDone:
1101 actionString =
@"TextInputAction.done";
1103 case FlutterTextInputActionGo:
1104 actionString =
@"TextInputAction.go";
1106 case FlutterTextInputActionSend:
1107 actionString =
@"TextInputAction.send";
1109 case FlutterTextInputActionSearch:
1110 actionString =
@"TextInputAction.search";
1112 case FlutterTextInputActionNext:
1113 actionString =
@"TextInputAction.next";
1115 case FlutterTextInputActionContinue:
1116 actionString =
@"TextInputAction.continueAction";
1118 case FlutterTextInputActionJoin:
1119 actionString =
@"TextInputAction.join";
1121 case FlutterTextInputActionRoute:
1122 actionString =
@"TextInputAction.route";
1124 case FlutterTextInputActionEmergencyCall:
1125 actionString =
@"TextInputAction.emergencyCall";
1127 case FlutterTextInputActionNewline:
1128 actionString =
@"TextInputAction.newline";
1131 [
self.textInputChannel invokeMethod:@"TextInputClient.performAction"
1132 arguments:@[ @(client), actionString ]];
1136 showAutocorrectionPromptRectForStart:(NSUInteger)start
1138 withClient:(
int)client {
1139 [
self.textInputChannel invokeMethod:@"TextInputClient.showAutocorrectionPromptRect"
1140 arguments:@[ @(client), @(start), @(end) ]];
1144 willDismissEditMenuWithTextInputClient:(
int)client {
1145 [
self.platformChannel invokeMethod:@"ContextMenu.onDismissSystemContextMenu"
1146 arguments:@[ @(client) ]];
1150 shareSelectedText:(NSString*)selectedText {
1151 [
self.platformPlugin showShareViewController:selectedText];
1155 searchWebWithSelectedText:(NSString*)selectedText {
1156 [
self.platformPlugin searchWeb:selectedText];
1160 lookUpSelectedText:(NSString*)selectedText {
1161 [
self.platformPlugin showLookUpViewController:selectedText];
1165 performContextMenuCustomActionWithActionID:(NSString*)actionID
1166 textInputClient:(
int)client {
1167 [
self.platformChannel invokeMethod:@"ContextMenu.onPerformCustomAction"
1168 arguments:@[ @(client), actionID ]];
1171#pragma mark - FlutterViewEngineDelegate
1177 [
self.textInputChannel invokeMethod:@"TextInputClient.showToolbar" arguments:@[ @(client) ]];
1181 focusElement:(UIScribbleElementIdentifier)elementIdentifier
1182 atPoint:(CGPoint)referencePoint
1187 [
self.textInputChannel
1188 invokeMethod:@"TextInputClient.focusElement"
1189 arguments:@[ elementIdentifier, @(referencePoint.x), @(referencePoint.y) ]
1194 requestElementsInRect:(CGRect)rect
1199 [
self.textInputChannel
1200 invokeMethod:@"TextInputClient.requestElementsInRect"
1201 arguments:@[ @(rect.origin.x), @(rect.origin.y), @(rect.size.width), @(rect.size.height) ]
1209 [
self.textInputChannel invokeMethod:@"TextInputClient.scribbleInteractionBegan" arguments:nil];
1216 [
self.textInputChannel invokeMethod:@"TextInputClient.scribbleInteractionFinished" arguments:nil];
1220 insertTextPlaceholderWithSize:(CGSize)size
1221 withClient:(
int)client {
1225 [
self.textInputChannel invokeMethod:@"TextInputClient.insertTextPlaceholder"
1226 arguments:@[ @(client), @(size.width), @(size.height) ]];
1230 removeTextPlaceholder:(
int)client {
1234 [
self.textInputChannel invokeMethod:@"TextInputClient.removeTextPlaceholder"
1235 arguments:@[ @(client) ]];
1239 didResignFirstResponderWithTextInputClient:(
int)client {
1243 [
self.textInputChannel invokeMethod:@"TextInputClient.onConnectionClosed"
1244 arguments:@[ @(client) ]];
1265 dispatch_async(dispatch_get_main_queue(), ^(
void) {
1266 long platform_view_id = [
self.platformViewsController firstResponderPlatformViewId];
1267 if (platform_view_id == -1) {
1271 [
self.platformViewsChannel invokeMethod:@"viewFocused" arguments:@(platform_view_id)];
1275#pragma mark - Undo Manager Delegate
1277- (void)handleUndoWithDirection:(FlutterUndoRedoDirection)direction {
1278 NSString*
action = (direction == FlutterUndoRedoDirectionUndo) ?
@"undo" :
@"redo";
1279 [
self.undoManagerChannel invokeMethod:@"UndoManagerClient.handleUndo" arguments:@[ action ]];
1282- (UIView<UITextInput>*)activeTextInputView {
1283 return [[
self textInputPlugin] textInputView];
1286- (NSUndoManager*)undoManager {
1287 return self.viewController.undoManager;
1290#pragma mark - Screenshot Delegate
1292- (
flutter::Rasterizer::Screenshot)takeScreenshot:(
flutter::Rasterizer::ScreenshotType)type
1293 asBase64Encoded:(
BOOL)base64Encode {
1295 return _shell->Screenshot(
type, base64Encode);
1298- (void)flutterViewAccessibilityDidCall {
1299 if (
self.viewController.view.accessibilityElements == nil) {
1300 [
self ensureSemanticsEnabled];
1304- (NSObject<FlutterBinaryMessenger>*)binaryMessenger {
1308- (NSObject<FlutterTextureRegistry>*)textureRegistry {
1322#pragma mark - FlutterBinaryMessenger
1324- (void)sendOnChannel:(NSString*)channel message:(NSData*)message {
1325 [
self sendOnChannel:channel message:message binaryReply:nil];
1328- (void)sendOnChannel:(NSString*)channel
1329 message:(NSData*)message
1333 @"Sending a message before the FlutterEngine has been run.");
1340 _shell->GetTaskRunners().GetPlatformTaskRunner());
1341 std::unique_ptr<flutter::PlatformMessage> platformMessage =
1342 (
message == nil) ? std::make_unique<flutter::PlatformMessage>(
channel.UTF8String, response)
1343 : std::make_unique<flutter::PlatformMessage>(
1346 _shell->GetPlatformView()->DispatchPlatformMessage(std::move(platformMessage));
1351- (NSObject<FlutterTaskQueue>*)makeBackgroundTaskQueue {
1356 binaryMessageHandler:
1358 return [
self setMessageHandlerOnChannel:channel binaryMessageHandler:handler taskQueue:nil];
1362 setMessageHandlerOnChannel:(NSString*)channel
1364 taskQueue:(NSObject<FlutterTaskQueue>* _Nullable)taskQueue {
1367 self.platformView->GetPlatformMessageHandlerIos()->SetMessageHandler(
channel.UTF8String,
1369 return [
self.connections acquireConnectionForChannel:channel];
1371 NSAssert(!
handler,
@"Setting a message handler before the FlutterEngine has been run.");
1373 return [FlutterConnectionCollection makeErrorConnectionWithErrorCode:-1L];
1379 NSString*
channel = [
self.connections cleanupConnectionWithID:connection];
1381 self.platformView->GetPlatformMessageHandlerIos()->SetMessageHandler(
channel.UTF8String, nil,
1387#pragma mark - FlutterTextureRegistry
1391 int64_t textureId =
self.nextTextureId++;
1392 self.platformView->RegisterExternalTexture(textureId,
texture);
1396- (void)unregisterTexture:(int64_t)textureId {
1397 _shell->GetPlatformView()->UnregisterTexture(textureId);
1400- (void)textureFrameAvailable:(int64_t)textureId {
1401 _shell->GetPlatformView()->MarkTextureFrameAvailable(textureId);
1404- (NSString*)lookupKeyForAsset:(NSString*)asset {
1408- (NSString*)lookupKeyForAsset:(NSString*)asset fromPackage:(NSString*)package {
1412- (
id<FlutterPluginRegistry>)pluginRegistry {
1416#pragma mark - FlutterPluginRegistry
1418- (NSObject<FlutterPluginRegistrar>*)registrarForPlugin:(NSString*)pluginKey {
1419 NSAssert(
self.pluginPublications[pluginKey] == nil,
@"Duplicate plugin key: %@", pluginKey);
1420 self.pluginPublications[pluginKey] = [NSNull null];
1422 flutterEngine:self];
1423 self.registrars[pluginKey] = result;
1427- (NSObject<FlutterApplicationRegistrar>*)registrarForApplication:(NSString*)key {
1428 NSAssert(
self.pluginPublications[
key] == nil,
@"Duplicate key: %@",
key);
1429 self.pluginPublications[key] = [NSNull null];
1432 self.registrars[key] = result;
1436- (
BOOL)hasPlugin:(NSString*)pluginKey {
1437 return _pluginPublications[pluginKey] != nil;
1440- (NSObject*)valuePublishedByPlugin:(NSString*)pluginKey {
1441 return _pluginPublications[pluginKey];
1444- (void)addSceneLifeCycleDelegate:(NSObject<FlutterSceneLifeCycleDelegate>*)delegate {
1445 [
self.sceneLifeCycleDelegate addDelegate:delegate];
1448#pragma mark - Notifications
1450- (void)sceneWillEnterForeground:(NSNotification*)notification API_AVAILABLE(ios(13.0)) {
1451 if (
self.viewController && ![
self.viewController shouldHandleSceneNotification:notification]) {
1454 [
self flutterWillEnterForeground:notification];
1457- (void)sceneDidEnterBackground:(NSNotification*)notification API_AVAILABLE(ios(13.0)) {
1458 if (
self.viewController && ![
self.viewController shouldHandleSceneNotification:notification]) {
1461 [
self flutterDidEnterBackground:notification];
1464- (void)applicationWillEnterForeground:(NSNotification*)notification {
1465 [
self flutterWillEnterForeground:notification];
1468- (void)applicationDidEnterBackground:(NSNotification*)notification {
1469 [
self flutterDidEnterBackground:notification];
1472- (void)flutterWillEnterForeground:(NSNotification*)notification {
1473 [
self setIsGpuDisabled:NO];
1476- (void)flutterDidEnterBackground:(NSNotification*)notification {
1477 [
self setIsGpuDisabled:YES];
1478 [
self notifyLowMemory];
1481- (void)onMemoryWarning:(NSNotification*)notification {
1482 [
self notifyLowMemory];
1485- (void)setIsGpuDisabled:(
BOOL)value {
1490 _isGpuDisabled =
value;
1493#pragma mark - Locale updates
1495- (void)onLocaleUpdated:(NSNotification*)notification {
1497 NSMutableArray<NSString*>* localeData = [[NSMutableArray alloc] init];
1498 NSArray<NSString*>* preferredLocales = [NSLocale preferredLanguages];
1499 for (NSString* localeID in preferredLocales) {
1500 NSLocale* locale = [[NSLocale alloc] initWithLocaleIdentifier:localeID];
1501 NSString* languageCode = [locale objectForKey:NSLocaleLanguageCode];
1502 NSString* countryCode = [locale objectForKey:NSLocaleCountryCode];
1503 NSString* scriptCode = [locale objectForKey:NSLocaleScriptCode];
1504 NSString* variantCode = [locale objectForKey:NSLocaleVariantCode];
1505 if (!languageCode) {
1508 [localeData addObject:languageCode];
1509 [localeData addObject:(countryCode ? countryCode : @"")];
1510 [localeData addObject:(scriptCode ? scriptCode : @"")];
1511 [localeData addObject:(variantCode ? variantCode : @"")];
1513 if (localeData.count == 0) {
1516 [
self.localizationChannel invokeMethod:@"setLocale" arguments:localeData];
1519- (void)onStatusBarTap {
1523 [
self.statusBarChannel invokeMethod:@"handleScrollToTop" arguments:nil];
1526- (void)waitForFirstFrameSync:(NSTimeInterval)timeout
1527 callback:(NS_NOESCAPE
void (^_Nonnull)(
BOOL didTimeout))callback {
1533- (void)waitForFirstFrame:(NSTimeInterval)timeout
1534 callback:(
void (^_Nonnull)(
BOOL didTimeout))callback {
1535 dispatch_queue_t
queue = dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0);
1536 dispatch_group_t group = dispatch_group_create();
1539 __block
BOOL didTimeout = NO;
1540 dispatch_group_async(group,
queue, ^{
1552 dispatch_group_notify(group, dispatch_get_main_queue(), ^{
1571 libraryURI:( NSString*)libraryURI
1572 initialRoute:( NSString*)initialRoute
1573 entrypointArgs:( NSArray<NSString*>*)entrypointArgs {
1574 NSAssert(
_shell,
@"Spawning from an engine without a shell (possibly not run).");
1576 project:self.dartProject
1577 allowHeadlessExecution:self.allowHeadlessExecution];
1579 [
self.dartProject runConfigurationForEntrypoint:entrypoint
1580 libraryOrNil:libraryURI
1581 entrypointArgs:entrypointArgs];
1583 configuration.
SetEngineId(result.engineIdentifier);
1597 [result recreatePlatformViewsController];
1599 initWithTaskRunner:shell.GetTaskRunners().GetPlatformTaskRunner()];
1600 return std::make_unique<flutter::PlatformViewIOS>(
1601 shell,
context, result.platformViewsController, shell.GetTaskRunners());
1605 [](
flutter::Shell& shell) {
return std::make_unique<flutter::Rasterizer>(shell); };
1607 std::string cppInitialRoute;
1609 cppInitialRoute = [initialRoute UTF8String];
1612 std::unique_ptr<flutter::Shell> shell =
_shell->Spawn(
1613 std::move(configuration), cppInitialRoute, on_create_platform_view, on_create_rasterizer);
1615 result->_threadHost = _threadHost;
1617 result->_isGpuDisabled = _isGpuDisabled;
1618 [result setUpShell:std::move(shell) withVMServicePublication:NO];
1622- (const
flutter::ThreadHost&)threadHost {
1623 return *_threadHost;
1627 return self.dartProject;
1630- (void)sendDeepLinkToFramework:(NSURL*)url completionHandler:(
void (^)(
BOOL success))completion {
1632 [
self waitForFirstFrame:3.0
1633 callback:^(BOOL didTimeout) {
1636 logError:@"Timeout waiting for first frame when launching a URL."];
1640 [weakSelf.navigationChannel
1641 invokeMethod:@"pushRouteInformation"
1643 @"location" : url.absoluteString ?: [NSNull null],
1645 result:^(id _Nullable result) {
1647 [result isKindOfClass:[NSNumber class]] && [result boolValue];
1651 logError:@"Failed to handle route information in Flutter."];
1653 completion(success);
1663- (instancetype)initWithKey:(NSString*)key flutterEngine:(
FlutterEngine*)flutterEngine {
1664 self = [
super init];
1665 NSAssert(
self,
@"Super init cannot be nil");