Reputation: 2227
I want to test at startup of the application , if the device is connected to the internet, if not display an alert notifying the user of the necessity to have the device connected to the internet, prevent him from starting the app if he is not connected, and at any time if he becomes disconnected, to reload the app, it's kind of like the principle of Clash of Clans…
At load test for internet, if no internet the app doesn't load..and at any time if the user looses connection, the app will restart. Any ideas how to do this?
Upvotes: 0
Views: 402
Reputation: 1195
To check the availability of connectivity Reachability class can be used. There is no API to exit the application programmatically quit my iOS application
Hope this helps.
Upvotes: 1
Reputation: 15335
Use the reachability library . include it in the AppDelegate:
internetReachability = [Reachability reachabilityWithHostname:@"www.google.com"];
// Internet is reachable
internetReachability.reachableBlock = ^(Reachability*reach)
{
// Update the UI on the main thread
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"Internet Connection Established");
// Update accordingly, use Storyboards or Navigation Stack
});
};
// Internet is not reachable
internetReachability.unreachableBlock = ^(Reachability*reach)
{
// Update the UI on the main thread
dispatch_async(dispatch_get_main_queue(), ^{
// Update accordingly, use Storyboards or Navigation Stack
});
};
[internetReachability startNotifier];
Upvotes: 1
Reputation: 22962
You can set internet as a requirement in the plist. See this post: My iPhone app needs a persistent network connection...how to specify UIRequiredDeviceCapabilities?
Upvotes: -1
Reputation: 8012
You can use Reachability to test for connectivity and have your app respond appropriately.
Upvotes: 0