Skip to content

Popups: Warning Popup

Charles Randolph edited this page Aug 31, 2017 · 4 revisions

Although identified as warningPopupButton in RGSBaseViewController, the Warning Popup would be better off called something like networkErrorPopup, given that it's basically hardwired to display a warning of network connectivity loss.

Implementation:

warningPopupButton is located in RGSBaseViewController, a sort of abstract class that all other view controllers in the tab view inherit from. Because RGSBaseViewController is only an abstract class, there exists no NIB off which this button initializes. Therefore, it is initialized and presented/dismissed programmatically from the Extensions.swift file in the Miscellaneous folder of the project alongside all other extensions. You should find the following methods there:

  1. displayWarningPopupIfNeeded
  2. displayWarningPopup
  3. dismissWarningPopup
  4. initWarningPopupButton

The popup depends on two boolean values in NetworkManager.swift in the Singletons folder to work.

  1. hasNetworkConnection
  2. userAcknowledgedNetworkError

It is necessary this exists in the Singleton as the state of the popup must be shared universally across all instances of RGSBaseViewController.

The method displayWarningPopupIfNeeded is called automatically in the viewWillAppear method of RGSBaseViewController.

Finally, control methods are also tied into the following methods available in all its subclasses (though these are not guaranteed or forced):

  1. refreshModelData
  2. scrollViewDidEndDragging

Behaviour:

This popup is designed to be displayed across all top level view controllers displayed in the tab view of the application. Since these are all subclasses of RGSBaseViewController, you can see why the functionality is based there.

The popup should display as soon as a network error has occurred, but only if the user hasn't acknowledged the problem. If the popup has been dismissed in one ViewController, it will no longer be visible in others until such a time that the user manually attempts to refresh the app contents. Doing this will reset the acknowledgment flag in the NetworkManager.swift singleton and it will be presented once more.

In short, display the warning if:

  1. There is NOT a network connection (hasNetworkConnection).
  2. The user has NOT acknowledged it (userAcknowledgedNetworkError).

Also note that userAcknowledgedNetworkError is reset in the following cases:

  1. If there IS a network connection.
  2. If the user executes a manual refresh.

Finally, please be aware that hasNetworkConnection is really more or less "has network connection to the application server". The user may well have internet access, but if the server can't be reached, the network connection error will be shown. This is somewhat alluded to by the warning popup message: "Can't call home. Check network connection!" in SpecificationManager.swift

Clone this wiki locally