0

I'm new in iOS app development and Swift.

What's my goal? On startup of my app I want to check the internet connection and the connection to my web server. These parts are implemented. And now I want to handle on it. If everything is fine I get a true and if anything is failed I get a false.

The first screen on startup should be a waiting view controller (viewController1) that displays something like "Please wait". I hope you know what I mean. This view controller is shown while checking the internet and server connection. After it I will go to the view controller that displays my content from server (viewController2), but only if the internet/server connection is true. if the internet/server connection is false I want to go to a third view controller (viewController3) to repeat the connection and to contact the support. But I don't know how I can do and where I can do this much simple.

I hope you can help me.

Thanks

Isuru
  • 30,617
  • 60
  • 187
  • 303
GRme
  • 2,707
  • 5
  • 26
  • 49
  • use storyboard. use scenes for EVERYTHING, even the smallest thing. link them all with segues. (no need to animate). it's the only way to go. so "check user exists" is a scene, "user wait (spinner)" is a different scene, "login" "wrong password" etc etc are all their OWN scene. it's the only way to go – Fattie Sep 24 '14 at 17:25
  • but how does it work? do you have a short example? – GRme Sep 24 '14 at 18:30

2 Answers2

2

you could create 3 ViewControllers in Storyboard and connect 1 (startup, login) to 2 (your content), and 1 to 3 (your support page).

Create a NavigationController and "Push" the other ViewControllers to your Main (View2) ViewController.

Then you could check on viewdidload on your initial View Controller (1) if your interent connection is fine and you get an response from your server. If true or false you could use:

performSegueWithIdentifier("yourSegueIdentifierToView2or3", sender: self)

to change the content.

And check this out: (Video about using ViewControllers Navigation in Swift)

https://www.youtube.com/watch?v=AQXWsDNno8o

derdida
  • 14,784
  • 16
  • 90
  • 139
  • this would work usually but with the current version of Xcode you would have to do two things for the ViewController to work. Add @objc Just BEFORE your Class of ViewController or change the ViewController.xib name to myProjectName.ViewController.xib – S.H. Sep 24 '14 at 17:11
  • Why he should need that? He did not say that he dont want to use Storyboard Editor. So this is normally a quite easy setup as shown in the tutorial video. – derdida Sep 24 '14 at 17:14
  • you are right. I wrongfully assume that. Hopefully it helps him anyways to know since he said he is new to the language. – S.H. Sep 24 '14 at 17:19
  • 1
    you don't have to bother with a nav controller. just segue from one to the other. – Fattie Sep 24 '14 at 17:25
1

@Derdida's suggested Answer would work usually but with the current version of Xcode you would have to do two things for the ViewController to work when being called with the method

performSegueWithIdentifier("yourSegueIdentifierToView2or3", sender: self) 

Add @objc Just BEFORE your Class of ViewController

Like this:

@objc public class MyClass : ViewController {
//Usual Class stuff
}

or change the ViewController.xib name to:

myProjectName.ViewController.xib

lastly for your specific situation of the "If there is internet connection or not"

Assuming that you already have the bool determining if the connection was established or not. use an If Statement right before using method "performSegue..." like this

var isConnectionEstablished: Bool = false

//Check Connection to set Bool

if (isConnectionEstablished == true) {
 performSegueWithIdentifier("yourSegueIdentifierToView2or3", sender: self) 
} else {

//Show some info to the user about the situation.
}

Hopefully this helps answer your questions.

Edit: Thanks to @Derdida to point this out... the first statement about @objc is if you are using Storyboard to make the ViewControllers Connection of your app.

S.H.
  • 2,833
  • 3
  • 26
  • 28