@@ -286,14 +286,46 @@ extension NUXViewControllerBase where Self: UIViewController, Self: UIViewContro
286286 private func setupNotificationsIndicator( ) {
287287 helpNotificationIndicator. isHidden = true
288288
289- NotificationCenter . default. addObserver ( forName: . wordpressSupportNotificationReceived, object: nil , queue: nil ) { [ weak self] _ in
289+ wordpressSupportNotificationReceivedObserver = NotificationCenter . default. addObserver ( forName: . wordpressSupportNotificationReceived, object: nil , queue: nil ) { [ weak self] _ in
290290 self ? . refreshSupportNotificationIndicator ( )
291291 }
292- NotificationCenter . default. addObserver ( forName: . wordpressSupportNotificationCleared, object: nil , queue: nil ) { [ weak self] _ in
292+ wordpressSupportNotificationClearedObserver = NotificationCenter . default. addObserver ( forName: . wordpressSupportNotificationCleared, object: nil , queue: nil ) { [ weak self] _ in
293293 self ? . refreshSupportNotificationIndicator ( )
294294 }
295295 }
296296
297+ private var wordpressSupportNotificationReceivedObserver : NSObjectProtocol ? {
298+ get {
299+
300+ objc_getAssociatedObject ( self , & wordpressSupportNotificationReceivedKey) as? NSObjectProtocol
301+ }
302+ set {
303+ objc_setAssociatedObject ( self , & wordpressSupportNotificationReceivedKey, newValue, . OBJC_ASSOCIATION_RETAIN)
304+ }
305+ }
306+
307+ private var wordpressSupportNotificationClearedObserver : NSObjectProtocol ? {
308+ get {
309+ objc_getAssociatedObject ( self , & wordpressSupportNotificationClearedKey) as? NSObjectProtocol
310+ }
311+ set {
312+ objc_setAssociatedObject ( self , & wordpressSupportNotificationClearedKey, newValue, . OBJC_ASSOCIATION_RETAIN)
313+ }
314+ }
315+
316+ func removeNotificationObservers( ) {
317+ if let wordpressSupportNotificationReceivedObserver {
318+ NotificationCenter . default. removeObserver ( wordpressSupportNotificationReceivedObserver)
319+ }
320+
321+ if let wordpressSupportNotificationClearedObserver {
322+ NotificationCenter . default. removeObserver ( wordpressSupportNotificationClearedObserver)
323+ }
324+
325+ wordpressSupportNotificationReceivedObserver = nil
326+ wordpressSupportNotificationClearedObserver = nil
327+ }
328+
297329 private func layoutNotificationIndicatorView( _ view: UIView , to superView: UIView ) {
298330 superView. addSubview ( view)
299331 view. translatesAutoresizingMaskIntoConstraints = false
@@ -323,3 +355,6 @@ extension NUXViewControllerBase where Self: UIViewController, Self: UIViewContro
323355 WordPressAuthenticator . shared. delegate? . presentSupport ( from: navigationController, sourceTag: source, lastStep: state. lastStep, lastFlow: state. lastFlow)
324356 }
325357}
358+
359+ private var wordpressSupportNotificationReceivedKey = 0
360+ private var wordpressSupportNotificationClearedKey = 0
0 commit comments