Reputation: 416
Okay. My app depends on having an active internet connection. When there isn't one, you may as well not be using it. Originally I was just going to present the user an alertView with options "retry connection" and "close app", but after a little research I found that Apple frown on apps closing themselves. So instead I decided to present an alertView with options "retry connection" and "wait", where the wait would take you to a relatively dull viewController, which would check for an internet connection periodically (once every 15 seconds or so). The idea of that is to bore the user into exiting the app for me with the home button, or to resume gameplay on the off chance the internet connection is re-established.
However, as you can imagine the internet access could go at any given time (when you're on any given view controller). This means that using segues is out of the question, because I would have to do a stupid amount of them, all going from every viewController to this one wait viewController.
Got any ideas? Is there a [self gotoViewControllerWithTitle:@"wait"]; command I don't know about?
I was thinking I could make all of my internet related stuff happen in one view controller I guess and just pass values to the other VCs if it came to it, but that seems very limiting/infantile.
Thank you in advanced and any help is appreciated :).
Upvotes: 0
Views: 175
Reputation: 627
Make your "no connection view controller" a singleton object. Then you can access this same instance using a class methods (e.g : [MyNoConnectionViewController shareInstance]).
Upvotes: 0
Reputation: 535
You could subclass 'UIViewController' to create your own base 'UIViewController' to have a generic method that checks the connection and on disconnect calls a modal view controller saying that the user has lost connection. And then maybe even pop to the root view controller. Then subclass that class and then every UIView Controller will now have the functionality you need. OOP FTW
On a side note, having a program that will only function with a working internet connection is a really bad idea. It's hard to keep the users hooked to an app when they'll be forced to quit the app when they lose connection.
Upvotes: 1
Reputation: 2522
Have your app delegate detect no internet, and present your Modal "No Internet" view controller. Then when internet returns "dismissModalViewController" and hey presto, your previous view controller is underneath.
Upvotes: 2