forked from firka/flutter
[iOS] Destroy the engine prior to application termination. (flutter/engine#29295)
This commit is contained in:
@@ -284,6 +284,11 @@ typedef enum UIAccessibilityContrast : NSInteger {
|
||||
name:UIApplicationWillResignActiveNotification
|
||||
object:nil];
|
||||
|
||||
[center addObserver:self
|
||||
selector:@selector(applicationWillTerminate:)
|
||||
name:UIApplicationWillTerminateNotification
|
||||
object:nil];
|
||||
|
||||
[center addObserver:self
|
||||
selector:@selector(applicationDidEnterBackground:)
|
||||
name:UIApplicationDidEnterBackgroundNotification
|
||||
@@ -816,6 +821,11 @@ static void SendFakeTouchEvent(FlutterEngine* engine,
|
||||
[self goToApplicationLifecycle:@"AppLifecycleState.inactive"];
|
||||
}
|
||||
|
||||
- (void)applicationWillTerminate:(NSNotification*)notification {
|
||||
[self goToApplicationLifecycle:@"AppLifecycleState.detached"];
|
||||
[self.engine destroyContext];
|
||||
}
|
||||
|
||||
- (void)applicationDidEnterBackground:(NSNotification*)notification {
|
||||
TRACE_EVENT0("flutter", "applicationDidEnterBackground");
|
||||
[self surfaceUpdated:NO];
|
||||
|
||||
@@ -124,6 +124,8 @@ typedef enum UIAccessibilityContrast : NSInteger {
|
||||
- (void)scrollEvent:(UIPanGestureRecognizer*)recognizer;
|
||||
- (void)updateViewportMetrics;
|
||||
- (void)onUserSettingsChanged:(NSNotification*)notification;
|
||||
- (void)applicationWillTerminate:(NSNotification*)notification;
|
||||
- (void)goToApplicationLifecycle:(nonnull NSString*)state;
|
||||
- (void)keyboardWillChangeFrame:(NSNotification*)notification;
|
||||
- (void)startKeyBoardAnimation:(NSTimeInterval)duration;
|
||||
- (void)ensureViewportMetricsIsCorrect;
|
||||
@@ -214,6 +216,20 @@ typedef enum UIAccessibilityContrast : NSInteger {
|
||||
OCMReject([viewControllerMock surfaceUpdated:[OCMArg any]]);
|
||||
}
|
||||
|
||||
- (void)testAppWillTerminateViewDidDestroyTheEngine {
|
||||
FlutterEngine* mockEngine = OCMPartialMock([[FlutterEngine alloc] init]);
|
||||
[mockEngine createShell:@"" libraryURI:@"" initialRoute:nil];
|
||||
FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:mockEngine
|
||||
nibName:nil
|
||||
bundle:nil];
|
||||
id viewControllerMock = OCMPartialMock(viewController);
|
||||
OCMStub([viewControllerMock goToApplicationLifecycle:@"AppLifecycleState.detached"]);
|
||||
OCMStub([mockEngine destroyContext]);
|
||||
[viewController applicationWillTerminate:nil];
|
||||
OCMVerify([viewControllerMock goToApplicationLifecycle:@"AppLifecycleState.detached"]);
|
||||
OCMVerify([mockEngine destroyContext]);
|
||||
}
|
||||
|
||||
- (void)testViewDidDisappearDoesPauseEngineWhenIsTheViewController {
|
||||
id lifecycleChannel = OCMClassMock([FlutterBasicMessageChannel class]);
|
||||
FlutterEnginePartialMock* mockEngine = [[FlutterEnginePartialMock alloc] init];
|
||||
|
||||
Reference in New Issue
Block a user