Parse API always Unreachable? - ios

I'm using Apple's Reachability framework, "api.parse.com" is ALWAYS Unreachable. Am I missing something?
In my viewDidLoad, I have this:
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(reachabilityChanged:) name:kReachabilityChangedNotification object:nil];
self.hostParseReachability = [Reachability reachabilityWithHostName:kParseConnectivityTestURL];
[self.hostParseReachability startNotifier];
[self updateInterfaceWithReachability:self.hostParseReachability];
Then I have the following Reachability methods:
-(void)reachabilityChanged:(NSNotification* )note
{
Reachability* curReach = [note object];
NSParameterAssert([curReach isKindOfClass:[Reachability class]]);
[self updateInterfaceWithReachability:curReach];
}
- (void)updateInterfaceWithReachability:(Reachability *)reachability {
NetworkStatus netStatus = [reachability currentReachabilityStatus];
if (reachability == self.internetReachability) {
switch (netStatus) {
case NotReachable:
isConnectedToInternet = NO;
break;
case ReachableViaWWAN:
case ReachableViaWiFi:
isConnectedToInternet = YES;
break;
}
}
if (reachability == self.hostParseReachability) {
switch (netStatus) {
case NotReachable:
isParseOnline = NO;
break;
case ReachableViaWWAN:
case ReachableViaWiFi:
isParseOnline = YES;
break;
}
}
Parse is ALWAYS offline for me, but I can perform queries.

They have a firewall blocking ICMP packets. If you need to check manually if everything is fine - you can try curl
If parse is unreachable, you'll get kPLParseConnectionFailed (in case of iOs app).

Related

Check for UIAlertViews on the screen from App Delegate

I have an issue with UIAlertView.
In my AppDelegate I check the reachability of the application:
If it is not reachable I call the alert from Utils class.
- (void)reachabilityChanged:(NSNotification *)note
{
Reachability* currentReachabilityObject = [note object];
NSParameterAssert([currentReachabilityObject isKindOfClass:[Reachability class]]);
NetworkStatus status = [currentReachabilityObject currentReachabilityStatus];
if (status == NotReachable)
{
[Utils showAlert:#"NotReachableNetwork") title:#"Error")];
}
}
And if I turn on/turn off Wi-Fi two-three times I get three alerts.
But I want to show only one.
Please tell me how to check is there any alerts on the screen from AppDelegate.
Why don't you keep a reference to the alert?
That way you just have to check if the alert is nil, if it is nil you can create a new alert. In case it isn't nil, it means you already have one showing and there's no need to show another. Easy as pie.
Please try below code and I think it will work for you.
#pragma mark - Internet Reachability Handlers -
- (void) updateInterfaceWithReachability: (Reachability*) curReach
{
NetworkStatus netStatus = [curReach currentReachabilityStatus];
if (_changeReachability)
{
if(netStatus==NotReachable)
{
[Utils showAlert:#"NotReachableNetwork") title:#"Error")];
_isNetAvailable = NO;
_changeReachability = NO;
}
else
{
_isNetAvailable = YES;
_changeReachability = NO;
}
}
}
//Called by Reachability whenever status changes.
- (void) reachabilityChanged: (NSNotification* )note
{
_changeReachability = YES;
Reachability* curReach = [note object];
NSParameterAssert([curReach isKindOfClass: [Reachability class]]);
[self updateInterfaceWithReachability: curReach];
}
-(void)checkallTypesofInternet
{
// For 3G Connection
hostReach = [Reachability reachabilityWithHostName:#"www.apple.com"];
[hostReach startNotifier];
[self updateInterfaceWithReachability: hostReach];
// For Individual Net Connection
internetReach = [Reachability reachabilityForInternetConnection];
[internetReach startNotifier];
[self updateInterfaceWithReachability: internetReach];
// For WiFi
wifiReach = [Reachability reachabilityForLocalWiFi];
[wifiReach startNotifier];
[self updateInterfaceWithReachability: wifiReach];
}
Let me know if you are still facing any issue.

reachability alway return NotReach

i use reachability to detect network change. the first time its ok with wifi available. but then i turn off wifi then turn on, it alway return NotReach
Reachability *internetChecker;
[[NSNotificationCenter defaultCenter]addObserver:self selector:#selector(myMethod:) name:kReachabilityChangedNotification object:nil];
internetChecker = [Reachability reachabilityWithHostName:#"www.24h.com.vn"];
[internetChecker startNotifier];
in mymethod:
NetworkStatus status = [internetChecker currentReachabilityStatus];
switch (status) {
case NotReachable:
{
NSLog(#"no wifi");
break;
}
default:
{
NSLog(#"wifi");
break;
}
}
Do you have separate Reachability properties for the Internet and the Host?
#property (nonatomic) Reachability *internetReachability;
#property (nonatomic) Reachability *hostReachability;
Then do this:
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(myMethod:) name:kReachabilityChangedNotification object:nil];
self.internetReachability = [Reachability reachabilityForInternetConnection];
[self.internetReachability startNotifier];
[self updateInterfaceWithReachability:self.internetReachability];
self.hostReachability = [Reachability reachabilityWithHostName:#"www.24h.com.vn"];
[self.hostReachability startNotifier];
[self updateInterfaceWithReachability:self.hostReachability];
Then myMethod:
- (void)myMethod:(NSNotification *)note
{
Reachability* curReach = [note object];
NSParameterAssert([curReach isKindOfClass:[Reachability class]]);
[self updateInterfaceWithReachability:curReach];
}
And updateInterfaceWithReachability:
- (void)updateInterfaceWithReachability:(Reachability *)reachability {
NetworkStatus netStatus = [reachability currentReachabilityStatus];
if (reachability == self.internetReachability) {
switch (netStatus) {
case NotReachable:
NSLog(#"no internet");
break;
case ReachableViaWWAN:
case ReachableViaWiFi:
NSLog(#"with internet");
break;
}
}
if (reachability == self.hostReachability) {
switch (netStatus) {
case NotReachable:
NSLog(#"www.24h.com.vn unavailable");
break;
case ReachableViaWWAN:
case ReachableViaWiFi:
NSLog(#"www.24h.com.vn available");
break;
}
}
Try below solution
+ (BOOL)checkInternetConnection
{
Reachability *reachability = [Reachability reachabilityForInternetConnection];
NetworkStatus remoteHostStatus = [reachability currentReachabilityStatus];
if (remoteHostStatus == NotReachable)
{
return FALSE;
}
else
{
return TRUE;
}
}
you have to modify this line
Reachability * internetChecker = [Reachability reachabilityForInternetConnection];
Hope it helps you..!
done! i dont know how but its seem notification center only detect when network change. When it notice the status is still NotReachable. So i check for the network after 2s delay. It work!

Internet connectivity returns false for cellular networks on iphone(xamarin.ios)

The following code returns true for wifi connection but false while checking for cellular(wwan) network on device ,
here is the code
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.google.com");
request.Timeout = 25000;
request.Credentials = CredentialCache.DefaultNetworkCredentials;
request.UseDefaultCredentials=true;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
return response.StatusCode == HttpStatusCode.OK;
}
catch (Exception e)
{
return false;
}
i am getting the error as
The remote server returned an error: (403) Forbidden
help out.
Check out Xamarin Reachability class here.
Edit:
Download and install the vodafone profile from http://db.tt/SqQGQ9Ci
You can use Reachibility
#import "Reachability.h"
+(bool)internetConnection
{
Reachability* reachability;
reachability = [Reachability reachabilityWithHostname:#"www.google.com"];
NetworkStatus netStatus = [reachability currentReachabilityStatus];
[reachability startNotifier];
switch (netStatus)
{
case NotReachable:
{
//[self showLoadingView:#"Internet Unavailable!!"];
[[NSNotificationCenter defaultCenter] postNotificationName:#"NetworkFail" object:self];
return NO;
break;
}
case ReachableViaWWAN:
{
[[NSNotificationCenter defaultCenter] postNotificationName:#"NEtworkPass" object:self];
return YES;
break;
}
case ReachableViaWiFi:
{
[[NSNotificationCenter defaultCenter] postNotificationName:#"NEtworkPass" object:self];
return YES;
break;
}
}
}

Trigger action immediately after connection is available

I want to trigger an action once the connection is available. There are solutions available which allows manually checking internet connection. One way i find is using NSTimer to check for internet connection during fixed intervals. But is it the most effective way to check for it? if Not, What is the right solution for this?
Here how you can register the observer and listen to it, Your application will be listening to kReachabilityChangedNotification & prompt you whenever status of network changes.
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(reachabilityHasChanged:) name:kReachabilityChangedNotification object:nil];
internetReachable = [[Reachability reachabilityForInternetConnection] retain];
[internetReachable startNotifier];
-(void) reachabilityHasChanged:(NSNotification *)notice
{
// called after network status changes
NetworkStatus internetStatus = [internetReachable currentReachabilityStatus];
switch (internetStatus)
{
case NotReachable:
{
NSLog(#"The internet is down.");
break;
}
case ReachableViaWiFi:
{
NSLog(#"The internet is working via WIFI.");
break;
}
case ReachableViaWWAN:
{
NSLog(#"The internet is working via WWAN.");
break;
}
}
}
Check reachability code provided by apple.In appdelegate.m you can see this method.It will notify the network change.Work on it
//Called by Reachability whenever status changes.
- (void) reachabilityChanged: (NSNotification* )note
{
Reachability* curReach = [note object];
NSParameterAssert([curReach isKindOfClass: [Reachability class]]);
[self updateInterfaceWithReachability: curReach];
}

Reachability host not reachable no matter which host I use

This case (NSLog(#"A gateway to the host server is down.");
is always running from some reason.
I'm using Apple Reachability class behind the scene.
I tried to insert other hosts but no luck please help.
Thanks in advance.
Here is the code
#implementation ConnectionManager
#synthesize internetActive, hostActive;
-(id)init {
self = [super init];
if(self) {
}
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(checkNetworkStatus:) name:#"NetworkReachabilityChangedNotification" object:nil];
internetReachable = [Reachability reachabilityForInternetConnection];
[internetReachable startNotifier];
hostReachable = [Reachability reachabilityWithHostName:#"www.google.com"];
[hostReachable startNotifier];
return self;
}
- (void) checkNetworkStatus:(NSNotification *)notice
{
NetworkStatus internetStatus = [internetReachable currentReachabilityStatus];
switch (internetStatus)
{
case NotReachable:
{
NSLog(#"The internet is down.");
self.internetActive = NO;
break;
}
case ReachableViaWiFi:
{
NSLog(#"The internet is working via WIFI.");
self.internetActive = YES;
break;
}
case ReachableViaWWAN:
{
NSLog(#"The internet is working via WWAN.");
self.internetActive = YES;
break;
}
}
NetworkStatus hostStatus = [hostReachable currentReachabilityStatus];
switch (hostStatus)
{
case NotReachable:
{
NSLog(#"A gateway to the host server is down.");
self.hostActive = NO;
break;
}
case ReachableViaWiFi:
{
NSLog(#"A gateway to the host server is working via WIFI.");
self.hostActive = YES;
break;
}
case ReachableViaWWAN:
{
NSLog(#"A gateway to the host server is working via WWAN.");
self.hostActive = YES;
break;
}
}
}
Since you haven't mentioned about internetReachable showing the same error, I am assuming that you are able to connect to internet and that part is working fine. For the hostReachable part, you can try to change it as:
Change
[Reachability reachabilityWithHostName:#"www.google.com"];
to
[Reachability reachabilityWithHostName:#"http://www.google.com"];

Resources