how to compare a NSURLconnection http response data with a string value in iphone? -


I am new to iPhone programming ... I want to do an activation module that will send an http request to a PIN number And then read the reaction ... If the reaction is "OK" it opens with a main menu ........... The problem is that I am receiving feedback as "OK" I am unable to compare with NSString @ "OK" ............, then how do http response with a string Mr. compare ........... please give ur suggestion ... thanks.

This is my piece of code ......

- Submit (IBAction): Partition: (ID) Sender {printf ("Submit BTN Inside"); Mydata = [NSMutableData alloc]; NSURLRequest * Request = [NSURLRequest requestWithURL: [NSURL URLWithString: @ ""] Cash Policy: NSURLRequestUseProtocolCachePolicy timeoutInterval: 60.0]; NSURLConnection * connection = [[NSURLConnection alloc] initWithRequest: Request Rep: Auto]; If (connection) {mydata = [[NSMutableData data] maintained]; } Else {// handle error: data not received printf ("no internet connection"); } {/ Code>

}

- (zero) connection: (NSURLConnection *) Connection done Rescount: (NSDTA *) incremental data {printf ("received data"); If (MyData == zero) {mydata = [[NSMUtableData Alloc] Initvid Capacity: 2048]; } [Mydata appendData: incremental data]; NSString * temp = [[NSString alloc] initWithData: mydata encoding: NSASCIIStringEncoding]; NSString * string1 = @ "OK"; NSUserDefaults * prefs = [NSUserDefaults standard user defaults]; If ([string1 isEqualToString: temp]) // // Here's the problem, STRINGS is not available [prefs setBool: for true: @ "activationKey"]; // Main Menu Main Menu Controller * MMC = [[Main Menu Controller Alloc] Init Whitneynam: @ Show "Main Menu" Bundle: [NSBindle Main Bundle]]; Self.mmainMenuController = MMC; [MMC release]; [Self.view addSubview: [mmmanu controller view]]; } Other {printf ("in else"); [Prefus Setball: For Fales Foreke: @ "Activation K"]; // Show a warning UIAlertView * alertActivationFail = [[UIAlertView alloc] initWithTitle: @ "Activation failed!" Message: @ "Pin is incorrect" Rep: Auto Cancel Button: @ "OK" other button titles: zero]; [Alert activation file show]; [Warning activation file release]; }

}


I will use the following Line, to see that the reaction is actually the correct string, because it may contain white space or other characters.

  NSLog (@ "string1 = '% @' temp = '% @', string1, taip);  

Previously this line has been entered ...

  NSString * string1 = "OK"; NSLog (@ "string1 = '% @' '='% @ '", string 1 ;); If ([String 1 Equaltoostring: Temp]) {// Here is the problem, STRINGS is not compatible  

If the reason for the extra whitepass is that the comparison is failing You can touch white space by using the following method े:

  + (NSString *) trim: (NSString *) value {return  
< / Html>

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -