I'm working on an iPhone application that makes a few calls to web services. I posted this application on the Apple store but it got rejected (and rightly so) since there was no error message displayed to the user if no Internet connection is available. Since obviously the application would not work without it.
So I just wanted to know how to best achieve this? I'm guessing something needs to go in the viewDidLoad
method that will throw an alert box saying something like "You need an Internet connection to use this application".
Any ideas would be appreciated.
To check if your iOS mobile device is connected to Wi-Fi:From the main screen of your device, look for and open Settings. With Settings open, look for the Wi-Fi field. Off - the Wi-Fi antenna is currently disabled. Not Connected - Wi-Fi is turned on, but your device is not currently connected to a network.
You can use the function usesInterfaceType(_:) to check which interface type this network path uses. This is the most effective way to figure out if your app is connected over WiFi, cellular or ethernet. print(“It's WiFi!”)
If your application must have network access the easiest way is to add the following settings to your info.plist as boolean values.
If your choice is not true then the user will be presented with an appropriate message when starting your application. Best of all this message is from the OS and thus is localized.
If your application cannot download data from a website while running (loss of signal, site down) you should still warn the user though and not just spin indefinitely.
Apple Developer Connection has a sample application (Reachability) that uses the System Configuration framework to determine network status. It will tell you whether you have a WiFi, EDGE/3G or no Internet connection.
You would use portions of this code in your application to determine network state, and then provide interface cues if no connection is available, such as a UIAlertView.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With