.h
- (void)checkForWIFIConnection;
.m
- (void)checkForWIFIConnection {
Reachability* wifiReach = [Reachability reachabilityForLocalWiFi];
NetworkStatus netStatus = [wifiReach currentReachabilityStatus];
if (netStatus!=ReachableViaWiFi)
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"No WIFI available!", @"AlertView")
message:NSLocalizedString(@"You have no wifi connection available. Please connect to a WIFI network.", @"AlertView")
delegate:self
cancelButtonTitle:NSLocalizedString(@"Cancel", @"AlertView")
otherButtonTitles:NSLocalizedString(@"Open settings", @"AlertView"), nil];
[alertView show];
}
}
- (void)viewDidLoad {
[super viewDidLoad];
[self checkForWIFIConnection]; // this does not show an alert...
[self parseXML]; // ...if this is here, but if i remove this line i get the UIALert saying no INTERNET
...
}
How do i make him only parse if the checkForInternetConnection does not fail?
I assume it's like if self Checkforwifi... { do this } else { do that}
But my checkforwifi is void, and does not return BOOL, i tried to change the method but since i'm kinda fairly new, i failed miserably.
Any help?
Cheers
- (BOOL)checkForWIFIConnection {
Reachability* wifiReach = [Reachability reachabilityForLocalWiFi];
NetworkStatus netStatus = [wifiReach currentReachabilityStatus];
if (netStatus!=ReachableViaWiFi)
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"No WIFI available!", @"AlertView")
message:NSLocalizedString(@"You have no wifi connection available. Please connect to a WIFI network.", @"AlertView")
delegate:self
cancelButtonTitle:NSLocalizedString(@"Cancel", @"AlertView")
otherButtonTitles:NSLocalizedString(@"Open settings", @"AlertView"), nil];
[alertView show];
return NO:
}
return YES;
}
- (void)viewDidLoad {
[super viewDidLoad];
if([self checkForWIFIConnection]) {
[self parseXML]; // ...if this is here, but if i remove this line i get the UIALert saying no INTERNET
}
}
return the status (a BOOL) and check it before calling parseXML, as seen above.