diff --git a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm index 3aa559414c6f5..e5549cfe33449 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm @@ -35,7 +35,6 @@ @interface FlutterEngine () @property(nonatomic, readonly) NSMutableDictionary* pluginPublications; @property(nonatomic, readwrite, copy) NSString* isolateId; -@property(nonatomic, retain) id flutterViewControllerWillDeallocObserver; @end @interface FlutterEngineRegistrar : NSObject @@ -118,7 +117,6 @@ - (void)dealloc { NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; [center removeObserver:self name:UIApplicationDidReceiveMemoryWarningNotification object:nil]; - [_flutterViewControllerWillDeallocObserver release]; [super dealloc]; } @@ -175,14 +173,11 @@ - (void)setViewController:(FlutterViewController*)viewController { _viewController = [viewController getWeakPtr]; self.iosPlatformView->SetOwnerViewController(_viewController); [self maybeSetupPlatformViewChannels]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onFlutterVCWillDeallocNotif:) name:FlutterViewControllerWillDealloc object:viewController]; +} - self.flutterViewControllerWillDeallocObserver = - [[NSNotificationCenter defaultCenter] addObserverForName:FlutterViewControllerWillDealloc - object:viewController - queue:[NSOperationQueue mainQueue] - usingBlock:^(NSNotification* note) { - [self notifyViewControllerDeallocated]; - }]; +- (void)onFlutterVCWillDeallocNotif:(NSNotification *)aNotification { + [self notifyViewControllerDeallocated]; } - (void)notifyViewControllerDeallocated { @@ -638,6 +633,7 @@ - (instancetype)initWithPlugin:(NSString*)pluginKey flutterEngine:(FlutterEngine } - (void)dealloc { + [[NSNotificationCenter defaultCenter] removeObserver:self]; [_pluginKey release]; [_flutterEngine release]; [super dealloc];