getting problem is that and how can solve this .I trying the internet is On than my must go for SYNC process .but i was work how can do this.
[TDatasyncmanager chekNetworkStatus:]':
:incompatible types in initialization
:switch quantity not an integer
I am trying to check the internet connection and host network connection like this
TDatasyncmanager.h file
#import "Reachability.h"
@interface TDatasyncmanager : UIViewController
{
Reachability *internetReachable;
Reachability *hostReachable;
BOOL internetActive;
NSMutableData *webData;
}
-(void)chekNetworkStatus:(NSNotification*)notice;
@end
And in TDatasyncmanager.m file
#import "TDatasyncmanager.h"
#import "Reachability.h"
@implementation TDatasyncmanager
@synthesize internetActive;
- (void)viewDidLoad {
[super viewDidLoad];
//check for internet connection
[[NSNotification defaultCenter] addObserver:self selector:@selector(checkNetworkStatus:) name:kReachabilityChangedNotification object:nil];
[internetReachable startNotifier];
//check for apathwa to arandom host exits
hostReachable = [[Reachability reachabilityWithHostName:@"http://www.google.com"]retain];
[hostReachable startNotifier];
if(internetActive == YES)
{
NSLog(@"tokenapi:%@ annan %@",tokenapi,Contentid);
NSString *post;
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSLog(@"%@",postLength);
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:@"http://192.168.0.1:88/"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
if (theConnection) {
webData = [[NSMutableData data] retain];
NSLog(@"%@",webData);
//[theConnection start];
}
}
}
-(void)chekNetworkStatus:(NSNotification *)notice
{
**//called after network status changes
NetworkStatus *internetStatus = [internetReachable currentReachabilityStatus];//:incompatible types in initialization
switch(internetStatus)//:switch quantity not an integer**
{
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;
}
default:
{
NSLog(@"The internet by defualt is Not working.");
self.internetActive = NO;
break;
}
}
NetworkStatus hostStatus = [hostReachable currentReachabilityStatus];
switch (hostStatus)
{
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;
}
default:
{
NSLog(@"the internet is down.");
self.internetActive= NO;
}
}
}
1 Answer