Ok, so I'm pretty new to Swift, and I'm a little confused about what I'm trying to do, or if I go in the wrong direction. ( https://github.com/ashleymills/Reachability.swift )
Here is my viewDidLoad method:
override func viewDidLoad() { super.viewDidLoad()
Then I have a function with code from the Reachability GitHub project:
func checkConnection() {
As you can see when there is no Internet, this is the code:
self.dim(direction: .In, alpha: self.dimLevel, speed: self.dimSpeed) self.performSegue(withIdentifier: "mainToAlertNoInternet", sender: self)
The Dim is taken from ( http://www.totem.training/swift-ios-tips-tricks-tutorials-blog/ux-chops-dim-the-lights ) mainToAlertNoInternet loads the next view on top of the current one with transparency, so itโs alert style .
So, the second segue has a view and a button on it. Nothing exciting is what loads when there is no Internet:

This button to try again is connected with the Segue output and launches this function in the First View controller:
@IBAction func unwindFromSecondary(segue: UIStoryboardSegue) { dim(direction: .Out, speed: dimSpeed) checkInternetConnection() }
I added mainToAlertNoInternet to the function mainToAlertNoInternet that when I click it again, it will return to the first session and run the test again. However, when I click the Retry button, I get this error:
A warning. Try to imagine whose view is not in the hierarchy of windows!
I hope I explained in sufficient detail what I created. Now to the questions:
1) How can I fix this error? 2) Am I doing it right or is there a better way?
This is what I want:
I want to check the Internet connection at the time of downloading the application. If there is no connection, I want to display the shogu, as I did. If the user clicks the Try Amplification button, I want him to return to the first controller and run the test again, and if the connection still does not appear, as it was done earlier. I would like this to be a repeating process until there is Internet access.
Appreciate all your help. thanks in advance
Edit:
I added a function call in the ViewDidAppear method as follows:
override func viewDidAppear(_ animated: Bool) { checkInternetConnection() }
However, it does not start. Also, the DIM in the unwindFromSecondary function unwindFromSecondary not called when I do this.
Edit 2:
Just added this line to my viewDidAppear :
print("Appeared")
It is called first, but not again.
Question:
How to get a function to run after everything has loaded again after unindSegue?
Any thoughts?
Update 3
Ok, so I reviewed the answers below:
@MarkP Answer works fine. Thank you for that. However, the answer from @iSee made me think, maybe I should figure it out differently.
I added Bounty to this post for a detailed answer that can show me and explain how to achieve the following:
In my application. I need to constantly ensure that the Internet exists (possibly a timer) in any view that is loading. I would like, as in the current case, if there is no Internet, it will pop up in the ViewController using this session:
performSegue(withIdentifier: "mainToAlertNoInernet", sender: self)
It looks like the app delegate will be the place, but I'm not sure how to do this.
I am new to iOS Development and will therefore be grateful for some explanation and teaching.
Thank you for your time. This is very valuable.