My application downloads updates from the server. To do this, he compares the data on the device with what is available on the server. If there is a mismatch, the logical "updateAvailable" is set to true, and an interactive UILabel is displayed to the user indicating that he can download the update.
(Simplified code)
class ViewController: UIViewController { @IBOutlet weak var updateLabel: UILabel! func updateChecker(){ let deviceVersion = self.settingsController.getDeviceVersion() //Get Server Version (Async) _ = settingsController.getServerVersion() { (data) -> () in dispatch_async(dispatch_get_main_queue()){ if deviceVersion != data{ self.updateAvailable = true } else{ self.updateAvailable = false } //Update UI self.updateUI() } } } func updateUI(){ if updateAvailable{ updateLabel.text = "Update Available" } else{ updateLabel.text = "App Up To Date" } }
When you touch this update label, the application launches the user transition to "updateViewController":
@IBAction func getUpdateLabelPressed(sender: UITapGestureRecognizer) { if updateAvailable{ self.performSegueWithIdentifier("segueToUpdateView", sender: self) }
UpdateViewController downloads data from the server (async) and then rejects:
class UpdateViewController: UIViewController{ override func viewDidLoad() { super.viewDidLoad() //Create Settings Controller + Get Update let sc = SettingsController() sc.getUpdate({ (success) -> () in if success{ dispatch_async(dispatch_get_main_queue()){ print("Update Success") self.dismissViewControllerAnimated(true, completion: nil) } } else{ dispatch_async(dispatch_get_main_queue()){ print("Update Failed") self.dismissViewControllerAnimated(true, completion: nil) } } }) }
When the UpdateViewController is fired, the main ViewController is displayed, however, 'updateAvailable' is still set to true, and updateLabel is still active.
Running another custom Segue back in the ViewController / Root ViewController is not an option for me, as it interrupts the background update selection, creating more than one instance of the "ViewController" on the stack.
onViewDidAppear () is also unacceptable in this case, as this can lead to heavy network / server traffic.
How can I reject the UpdateViewController AND Reload the previous ViewController ViewController OR Send data that runs the ViewController updateChecker () method? OR clear the entire ViewControllerStack and restart the application?
I understand that a delegate arrangement seems appropriate, but previous SO questions and answers on this topic, such as this> for Objective-C, and I was not able to adapt these answers for Swift 2.0.
Any help would be greatly appreciated.