I am creating a "no internet connection". This is for opening an app without internet connection. So first I added this code to my bridge.h
import "Reachability.h"
Then add following method to reachability class. First declare in .h file :
+ (BOOL)checkIntenetRechable;
and implement in .m file
+ (BOOL)checkIntenetRechable
{
BOOL isInternetAvailable;
Reachability *internetReach = [Reachability reachabilityForInternetConnection];
[internetReach startNotifier];
NetworkStatus netStatus = [internetReach currentReachabilityStatus];
BOOL connectionRequired = [internetReach connectionRequired];
NSString *statusString = @"";
switch (netStatus)
{
case NotReachable:
{
statusString = @"Access Not Available";
isInternetAvailable = FALSE;
break;
}
case ReachableViaWWAN:
{
statusString = @"Reachable WWAN";
isInternetAvailable = TRUE;
break;
}
case ReachableViaWiFi:
{
statusString = @"Reachable WiFi";
isInternetAvailable = TRUE;
break;
}
}
if(connectionRequired)
{
statusString = [NSString stringWithFormat: @"%@, Connection Required", statusString];
isInternetAvailable = FALSE;
}
return isInternetAvailable;
}
Then wherever I want to check internet connection I put the following snippet there and alert user about it.
if Reachability.checkIntenetRechable() == false {
let alertView = UIAlertCole: "APP_NAME", message: "Please check your internet connection.", preferredStyle: UIAlertControllerStyle.Alert)
//alertView.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel, handler: { (action: UIAlertAction ) in }))
alertView.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: { (action: UIAlertAction ) in
// Put some code for okay button
}))
self.presentViewController(alertView, animated: true, completion: nil)
}
AND after awhile I got This error...what could be the problem??