Skip to content

Commit

Permalink
Merge pull request #22 from ivpn/task/IOS-697-unneeded-notificationce…
Browse files Browse the repository at this point in the history
…nter-removal-violation

Task/IOS-697 Unneeded NotificationCenter Removal Violation
  • Loading branch information
jurajhilje authored Oct 8, 2020
2 parents 50ae924 + 2aa2999 commit 42adf72
Show file tree
Hide file tree
Showing 11 changed files with 1 addition and 99 deletions.
1 change: 0 additions & 1 deletion IVPNClient/Managers/VPNErrorObserver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class VPNErrorObserver {
}

deinit {
NotificationCenter.default.removeObserver(self, name: Notification.Name.VPNConnectError, object: nil)
wireguardErrorObserver?.invalidate()
wireguardErrorObserver = nil
}
Expand Down
8 changes: 0 additions & 8 deletions IVPNClient/Scenes/AccountScreen/AccountViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,12 @@ class AccountViewController: UITableViewController {
accountView.initQRCode(viewModel: viewModel)
}

deinit {
removeObservers()
}

// MARK: - Observers -

func addObservers() {
NotificationCenter.default.addObserver(self, selector: #selector(subscriptionActivated), name: Notification.Name.SubscriptionActivated, object: nil)
}

func removeObservers() {
NotificationCenter.default.removeObserver(self, name: Notification.Name.SubscriptionActivated, object: nil)
}

// MARK: - Private methods -

private func initNavigationBar() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,6 @@ class ControlPanelViewController: UITableViewController {
NotificationCenter.default.removeObserver(self, name: Notification.Name.PingDidComplete, object: nil)
}

deinit {
removeObservers()
}

// MARK: - Gestures -

private func setupGestureRecognizers() {
Expand Down Expand Up @@ -372,21 +368,6 @@ class ControlPanelViewController: UITableViewController {
NotificationCenter.default.addObserver(self, selector: #selector(protocolSelected), name: Notification.Name.ProtocolSelected, object: nil)
}

private func removeObservers() {
NotificationCenter.default.removeObserver(self, name: Notification.Name.UpdateControlPanel, object: nil)
NotificationCenter.default.removeObserver(self, name: Notification.Name.ServerSelected, object: nil)
NotificationCenter.default.removeObserver(self, name: Notification.Name.Connect, object: nil)
NotificationCenter.default.removeObserver(self, name: Notification.Name.Disconnect, object: nil)
NotificationCenter.default.removeObserver(self, name: Notification.Name.AuthenticationDismissed, object: nil)
NotificationCenter.default.removeObserver(self, name: Notification.Name.SubscriptionDismissed, object: nil)
NotificationCenter.default.removeObserver(self, name: Notification.Name.ServiceAuthorized, object: nil)
NotificationCenter.default.removeObserver(self, name: Notification.Name.SubscriptionActivated, object: nil)
NotificationCenter.default.removeObserver(self, name: Notification.Name.NewSession, object: nil)
NotificationCenter.default.removeObserver(self, name: Notification.Name.ForceNewSession, object: nil)
NotificationCenter.default.removeObserver(self, name: Notification.Name.ProtocolSelected, object: nil)
NotificationCenter.default.removeObserver(self, name: Notification.Name.TermsOfServiceAgreed, object: nil)
}

// MARK: - Private methods -

private func initView() {
Expand Down
7 changes: 0 additions & 7 deletions IVPNClient/Scenes/MainScreen/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ class MainViewController: UIViewController {
}

deinit {
removeObservers()
updateServersTimer.invalidate()
Application.shared.connectionManager.removeStatusChangeUpdates()
}
Expand Down Expand Up @@ -172,12 +171,6 @@ class MainViewController: UIViewController {
NotificationCenter.default.addObserver(self, selector: #selector(subscriptionActivated), name: Notification.Name.SubscriptionActivated, object: nil)
}

private func removeObservers() {
NotificationCenter.default.removeObserver(self, name: Notification.Name.UpdateFloatingPanelLayout, object: nil)
NotificationCenter.default.removeObserver(self, name: Notification.Name.VPNConfigurationDisabled, object: nil)
NotificationCenter.default.removeObserver(self, name: Notification.Name.SubscriptionActivated, object: nil)
}

// MARK: - Private methods -

@objc private func updateFloatingPanelLayout() {
Expand Down
14 changes: 0 additions & 14 deletions IVPNClient/Scenes/MainScreen/Map/MapMarkerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,6 @@ class MapMarkerView: UIView {
super.updateConstraints()
}

deinit {
removeObservers()
}

// MARK: - Methods -

func updateCircles(color: UIColor) {
Expand Down Expand Up @@ -166,16 +162,6 @@ class MapMarkerView: UIView {
}
}

private func removeObservers() {
NotificationCenter.default.removeObserver(self, name: Notification.Name.HideConnectionInfoPopup, object: nil)

if #available(iOS 13.0, *) {
NotificationCenter.default.removeObserver(self, name: UIScene.didActivateNotification, object: nil)
} else {
NotificationCenter.default.removeObserver(self, name: UIApplication.didBecomeActiveNotification, object: nil)
}
}

// MARK: - Private methods -

private func setupConstraints() {
Expand Down
10 changes: 0 additions & 10 deletions IVPNClient/Scenes/MainScreen/Map/MapScrollView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ class MapScrollView: UIScrollView {
addObservers()
}

deinit {
removeObservers()
}

// MARK: - Methods -

func setupConstraints() {
Expand Down Expand Up @@ -147,12 +143,6 @@ class MapScrollView: UIScrollView {
NotificationCenter.default.addObserver(self, selector: #selector(hideConnectToServerPopup), name: Notification.Name.HideConnectToServerPopup, object: nil)
}

private func removeObservers() {
NotificationCenter.default.removeObserver(self, name: Notification.Name.ServerSelected, object: nil)
NotificationCenter.default.removeObserver(self, name: Notification.Name.PingDidComplete, object: nil)
NotificationCenter.default.removeObserver(self, name: Notification.Name.HideConnectToServerPopup, object: nil)
}

private func initGestures() {
let tap = UITapGestureRecognizer(target: self, action: #selector(handleTap))
addGestureRecognizer(tap)
Expand Down
8 changes: 0 additions & 8 deletions IVPNClient/Scenes/MainScreen/View/MainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ class MainView: UIView {
}
}

deinit {
removeObservers()
}

// MARK: - Methods -

func setupView(animated: Bool = true) {
Expand Down Expand Up @@ -99,10 +95,6 @@ class MainView: UIView {
NotificationCenter.default.addObserver(self, selector: #selector(centerMap), name: Notification.Name.CenterMap, object: nil)
}

private func removeObservers() {
NotificationCenter.default.removeObserver(self, name: Notification.Name.CenterMap, object: nil)
}

private func initSettingsAction() {
let settingsButton = UIButton()
addSubview(settingsButton)
Expand Down
12 changes: 0 additions & 12 deletions IVPNClient/Scenes/Signup/LoginViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,6 @@ class LoginViewController: UIViewController {
}
}

deinit {
removeObservers()
}

// MARK: - Observers -

func addObservers() {
Expand All @@ -134,14 +130,6 @@ class LoginViewController: UIViewController {
NotificationCenter.default.addObserver(self, selector: #selector(termsOfServiceAgreed), name: Notification.Name.TermsOfServiceAgreed, object: nil)
}

func removeObservers() {
NotificationCenter.default.removeObserver(self, name: Notification.Name.SubscriptionDismissed, object: nil)
NotificationCenter.default.removeObserver(self, name: Notification.Name.SubscriptionActivated, object: nil)
NotificationCenter.default.removeObserver(self, name: Notification.Name.NewSession, object: nil)
NotificationCenter.default.removeObserver(self, name: Notification.Name.ForceNewSession, object: nil)
NotificationCenter.default.removeObserver(self, name: Notification.Name.TermsOfServiceAgreed, object: nil)
}

@objc func newSession() {
startLoginProcess()
}
Expand Down
6 changes: 1 addition & 5 deletions IVPNClient/Scenes/Signup/Scanner/ScannerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@ class ScannerViewController: UIViewController, AVCaptureMetadataOutputObjectsDel
stopCaptureSession()
}

deinit {
NotificationCenter.default.removeObserver(self, name: UIDevice.orientationDidChangeNotification, object: nil)
}

// MARK: - Orientation -

override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
Expand Down Expand Up @@ -164,7 +160,7 @@ class ScannerViewController: UIViewController, AVCaptureMetadataOutputObjectsDel
}

private func allowCameraAccessViaSetting() {
showActionAlert(title: "Allow Camera", message: "Camera access is required to scan QR code", action: "Open Settings", actionHandler: { _ in
showActionAlert(title: "Allow Camera", message: "Camera access is required to scan QR code", action: "Open Settings", actionHandler: { _ in
if let url = URL(string: UIApplication.openSettingsURLString) {
UIApplication.shared.open(url)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ class NetworkProtectionViewController: UITableViewController {
NotificationCenter.default.addObserver(self, selector: #selector(loadHandler), name: Notification.Name.NetworkSaved, object: nil)
}

deinit {
NotificationCenter.default.removeObserver(self)
}

// MARK: - Interface Orientations -

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
Expand Down
11 changes: 0 additions & 11 deletions IVPNClient/Scenes/ViewControllers/SettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,6 @@ class SettingsViewController: UITableViewController {
NotificationCenter.default.removeObserver(self, name: Notification.Name.PingDidComplete, object: nil)
}

deinit {
removeObservers()
}

// MARK: - Segues -

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
Expand Down Expand Up @@ -304,13 +300,6 @@ class SettingsViewController: UITableViewController {
NotificationCenter.default.addObserver(self, selector: #selector(authenticationDismissed), name: Notification.Name.AuthenticationDismissed, object: nil)
}

func removeObservers() {
NotificationCenter.default.removeObserver(self, name: Notification.Name.TurnOffMultiHop, object: nil)
NotificationCenter.default.removeObserver(self, name: Notification.Name.TermsOfServiceAgreed, object: nil)
NotificationCenter.default.removeObserver(self, name: Notification.Name.ServiceAuthorized, object: nil)
NotificationCenter.default.removeObserver(self, name: Notification.Name.AuthenticationDismissed, object: nil)
}

@objc func turnOffMultiHop() {
UserDefaults.shared.set(false, forKey: UserDefaults.Key.isMultiHop)
multiHopSwitch.setOn(false, animated: false)
Expand Down

0 comments on commit 42adf72

Please sign in to comment.