i am new in iphone programming......i want to do an activation module which will send a http request with a PIN numbr and then read the response...if the response is "OK" it opens up with a main menu...........the problem is that i am recieving the response as "OK" but i am unable to compare it with a NSString @"OK"............so how to compare the http response with a string...........please give ur suggestions...thanks.
Here is my piece of code......
-(IBAction) submitPINAction:(id) sender { printf("inside submit btn"); mydata = [NSMutableData alloc]; NSURLRequest *request = [NSURLRequest requestWithURL: [NSURL URLWithString:@"http://192.168.100.3/WWTF/activationApp.php?PIN=11111"]
cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
NSURLConnection *connection=[[NSURLConnection alloc] initWithRequest:request delegate:self];
if(connection)
{
mydata = [[NSMutableData data] retain];
}
else
{
//Handle error : Not received data
printf("No internet connection");
}
}
-(void)connection:(NSURLConnection *)theConnection didReceiveData:(NSData *)incrementalData { printf("data received"); if (mydata==nil) { mydata = [[NSMutableData alloc] initWithCapacity:2048]; } [mydata appendData:incrementalData]; NSString *temp = [[NSString alloc] initWithData:mydata encoding:NSASCIIStringEncoding];
NSString *string1 = @"OK";
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
if([string1 isEqualToString:temp]){ // HERE IS THE PROBLEM, THE STRINGS ARE NOT GETTIN COMPARED
[prefs setBool:TRUE forKey: @"activationKey"];
// show the main menu
mainMenuController *mmC = [[mainMenuController alloc]initWithNibName:@"mainMenu" bundle:[NSBundle mainBundle]];
self.mmainMenuController = mmC;
[mmC release];
[self.view addSubview:[mmainMenuController view]];
}
else{
printf("in else");
[prefs setBool:FALSE forKey: @"activationKey"];
//show an alert
UIAlertView *alertActivationFail = [[UIAlertView alloc] initWithTitle:@"Activation Failed!" message:@"PIN is Incorrect" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertActivationFail show];
[alertActivationFail release];
}
}