PIN 番号を使用して http 要求を送信し、応答を読み取るアクティベーション モジュールを実行したいと考えています。応答が「OK」の場合、メイン メニューが開きます。問題は、「OK」として応答を受信していることですが、それを NSString @「OK」と比較できないことです。http 応答を文字列と比較する方法は?
これが私のコードです:
-(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];
}
}