I am using this code for detecting if there is internet connection:
Reachability *networkReachability = [Reachability reachabilityForInternetConnection];
NetworkStatus networkStatus = [networkReachability currentReachabilityStatus];
if (networkStatus == NotReachable) {
[UIView showSimpleAlertWithTitle:nil
message:locs(#"8614aa-alert_connection_message", lpos_alert_message)
cancelButtonTitle:#"OK"];
return;
}
It works. But I have problem when there is cellular data connection and my app is blocked. It returns WWAN but I can't connect. So how can I detect if my app is blocked or not? Thanks
Related
I have in my app check with Reachability check, but in one device in 4G its return me a NotReachable even the iPhone get Facebook messages and whatsapp.
if the iPhone in wifi this work grate.
what can be the problem ?
-(BOOL)isConnectedToInternet {
Reachability *networkReachability = [Reachability reachabilityWithHostName:HOST_NAME];
NetworkStatus networkStatus = [networkReachability currentReachabilityStatus];
return networkStatus != NotReachable;
}
I have always had problems with Reachability. I tend not to use it now and just make the network call. AFNetworking will fail with an NSError with code kCFURLErrorNotConnectedToInternet (-1009) if there's no network.
I am checking the status of internet reachability using class "Reachability". But while testing, if I am setting 100% packet loss in developer settings, still I get reachability status as "ReachableViaWiFi". I am confused what's happening. Shouldn't it be "NotReachable" in that situation ?
Here is my code snippet:
Reachability *networkReachability = [Reachability reachabilityForInternetConnection];
NetworkStatus networkStatus = [networkReachability currentReachabilityStatus];
if(networkStatus == NotReachable){
NSLog(#"NotReachable");
}
else if(networkStatus == ReachableViaWiFi){
NSLog(#"ReachableViaWiFi");
}
else if(networkStatus == ReachableViaWWAN){
NSLog(#"ReachableViaWWAN");
}
Is there any other way that give me status as FALSE in this situation?
The number of packets that you lose doesn't influence reachability. After all, this could be just momentary (you took your phone into a shielded room, or a heavy electrical motor was just turned on). Reachability is about your WiFi, or 3G, or Ethernet on a Mac, being turned on. It's not about the quality of the connection.
This worked for me:
-(BOOL)connected
{
Reachability *r = [Reachability reachabilityWithHostName:#"www.google.com"];
NetworkStatus internetStatus = [r currentReachabilityStatus];
if ((internetStatus != ReachableViaWiFi) && (internetStatus != ReachableViaWWAN))
{
return NO;
}
else
{
return YES;
}
}
Can i check the state of wifi service. Is it enable or disable if user phone not connected to WiFi. I need it for create user alert, because i need WIFi state at "ON" state for my app with navigation.
For this you need to import reachability classes in your project.
BOOL isConnectedProperly = ([[Reachability reachabilityForInternetConnection] currentReachabilityStatus] == ReachableViaWiFi);
Ref:
https://developer.apple.com/library/ios/samplecode/Reachability/Introduction/Intro.html
https://github.com/tonymillion/Reachability
Use Reachability Class for checking the network connection state
Reachability *internetReachable=[Reachability reachabilityForInternetConnection];
if(internetReachable.currentReachabilityStatus == ReachableViaWiFi)
{
wifiAvailable=YES;
}
else
{
// Show the alert to turn on wifi
}
Using the code apple provide https://developer.apple.com/iphone/library/samplecode/Reachability
Reachability *reachability = [Reachability reachabilityForInternetConnection];
[reachability startNotifier];
NetworkStatus status = [reachability currentReachabilityStatus];
if(status == NotReachable)
{
//No internet
}
else if (status == ReachableViaWiFi)
{
//WiFi
}
else if (status == ReachableViaWWAN)
{
//3G
}
I have problem with detect sim, i was used CTCarry but not dectect when device "No Service" , Please help me how to detect it.
Use the Reachability class from Apple:
Reachability *reachability = [Reachability reachabilityForInternetConnection];
[reachability startNotifier];
NetworkStatus status = [reachability currentReachabilityStatus];
switch(status) {
case NotReachable:
return #"No Service";
case ReachableViaWiFi:
...
}
Alternatively you can use the SCNetworkReachability class directly.
I am using Reachability in my IOS app to determine a connection.
Following from this post wifi on iphone simulator
If the wifi is turned off the internet connection for the simulator is not available but the phone is still connected to Wifi therefore a connection has not changed. This is all fine and understood and of course I can test on the device itself.
However, I am looking to handle the error that a user is connected to wifi but the wifi has no internet connection like the screenshot below.
I use reachability in the following way:
#pragma mark - ()
- (void)monitorReachability {
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(reachabilityChanged:) name:ReachabilityChangedNotification object:nil];
self.hostReach = [Reachability reachabilityWithHostname: #"api.parse.com"];
[self.hostReach startNotifier];
self.internetReach = [Reachability reachabilityForInternetConnection];
[self.internetReach startNotifier];
self.wifiReach = [Reachability reachabilityForLocalWiFi];
[self.wifiReach startNotifier];
}
//Called by Reachability whenever status changes.
- (void)reachabilityChanged:(NSNotification* )note {
Reachability *curReach = (Reachability *)[note object];
NSParameterAssert([curReach isKindOfClass: [Reachability class]]);
NSLog(#"Reachability changed: %#", curReach);
networkStatus = [curReach currentReachabilityStatus];
}
I am using Reachability for ARC from tonymillion's github here: https://github.com/tonymillion/Reachability
Does anyone know how I can handle this situation of connection with a better error?
create following method in appdelegate to use it on any class.
-(BOOL)isHostAvailable
{
//return NO; // force for offline testing
Reachability *hostReach = [Reachability reachabilityForInternetConnection];
NetworkStatus netStatus = [hostReach currentReachabilityStatus];
return !(netStatus == NotReachable);
}