|
54 | 54 |
|
55 | 55 | // Add an observer that will clear out the owner_controller_ ivar and |
56 | 56 | // the accessibility_bridge_ in case the view controller is deleted. |
57 | | - dealloc_view_controller_observer_.reset([[NSNotificationCenter defaultCenter] |
58 | | - addObserverForName:FlutterViewControllerWillDealloc |
59 | | - object:owner_controller_.get() |
60 | | - queue:[NSOperationQueue mainQueue] |
61 | | - usingBlock:^(NSNotification* note) { |
62 | | - // Implicit copy of 'this' is fine. |
63 | | - accessibility_bridge_.reset(); |
64 | | - owner_controller_.reset(); |
65 | | - }]); |
| 57 | + dealloc_view_controller_observer_.reset( |
| 58 | + [[[NSNotificationCenter defaultCenter] addObserverForName:FlutterViewControllerWillDealloc |
| 59 | + object:owner_controller_.get() |
| 60 | + queue:[NSOperationQueue mainQueue] |
| 61 | + usingBlock:^(NSNotification* note) { |
| 62 | + // Implicit copy of 'this' is fine. |
| 63 | + accessibility_bridge_.reset(); |
| 64 | + owner_controller_.reset(); |
| 65 | + }] retain]); |
66 | 66 |
|
67 | 67 | if (owner_controller_) { |
68 | 68 | ios_surface_ = |
@@ -174,4 +174,23 @@ new AccessibilityBridge(static_cast<FlutterView*>(owner_controller_.get().view), |
174 | 174 | text_input_plugin_ = plugin; |
175 | 175 | } |
176 | 176 |
|
| 177 | +PlatformViewIOS::ScopedObserver::ScopedObserver() : observer_(nil) {} |
| 178 | + |
| 179 | +PlatformViewIOS::ScopedObserver::~ScopedObserver() { |
| 180 | + if (observer_) { |
| 181 | + [[NSNotificationCenter defaultCenter] removeObserver:observer_]; |
| 182 | + [observer_ release]; |
| 183 | + } |
| 184 | +} |
| 185 | + |
| 186 | +void PlatformViewIOS::ScopedObserver::reset(id<NSObject> observer) { |
| 187 | + if (observer != observer_) { |
| 188 | + if (observer_) { |
| 189 | + [[NSNotificationCenter defaultCenter] removeObserver:observer_]; |
| 190 | + [observer_ release]; |
| 191 | + } |
| 192 | + observer_ = observer; |
| 193 | + } |
| 194 | +} |
| 195 | + |
177 | 196 | } // namespace flutter |
0 commit comments