Getting data from server in objective c class -


I am trying to create a square where I will create an example of that class and send the username and password to the class. Returns to the server and gives it whether it is a valid password or what is the error. When I try to reach the response variable from the example, I get blank. I suspect that the methods start up - (zero) connection DIDFinish Loading: (NSURLConnection *) is occurring before the use of the connection variable.

@interface loginViewController: UIViewController - (IBAction is a better way to access the variable or call the method before reaching the validity) login: (id) this ; @protecti (nanatomic, rtain) iBotlet UItextfiled * Username; @ Property (non-standard, reserved) IBOutlet UIT ext file * password; @end

Login view controller. M

  #import "LoginViewController.h" #import "users.h" @interface LoginViewController () @end @ implementation LoginViewController @ synthesis username, password; / * - (IBAction) Login: (ID) sender {user * user = [[user allocation] init]; [User login: username.text: password.text]; If ([user.serverResponseEqual is: @ "Status: Created"]) {[Self Performance Cigu with Identifier: @ "home" sender: zero]; } Else {UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @ "" Message: @ "Username or password is incorrect" Rep: Automatically cancelTuttonite: @ "Cancel" other button titles: @ "OK", zero]; [Alerts show]; } NSLog (@ "% @", user.serverResponse); } @end   

User class .h

  #import & lt; Foundation / Foundation. H & gt; @ Interface User: NSBKect - (zero) login: (NSString *) Username: (NSString *) password; - (zero) signup: (NSString *) Username: (NSString *) Password: (NSString *) password_confirmation: (NSString *) email; @property (nonatomic, retain) NSMutableData * response; @protecti (nonomatic, retaining) NSString * serverResponse; @end   

User class.m

  #import "users.h" #define loginURL @ "linktoserver" #define signupURL @ "Link Tangenter" @ Permissions user @ synthesis response, server response; - (zero) login: (NSString *) Username: (NSString *) password {NSMutableData * data = [[NSMutableData alloc] init]; Self.response = data; NSURL * url = [NSURL URLWithString: loginURL]; NSMutableURLRequest * Request = [URL with NSMutableURL request request: [url standardizedURL]]; // HTTP method [HTTPS system requesting: @ "post"]; // Intializes Post Data NSString * postData = [NSString stringWithFormat: @ "Username =% @ and password =% @", username, password]; NSString * postLength = [NSString stringWithFormat: @ "% lu", (unsigned long) [postdata length]]; [Set set property: post length for http header field: @ "content-length"]; [Request Set Value: @ "App / JSN" HTTP Headerfield: @ "Acceptor"]; [Request Set Value: @ "App / X-www-Form-URLXode" forHTTPHeaderField: @ "Content-Type"]; [Request [httpBBDI]: [PostData DataSubmission Encoding: NSUTF 8 string encoding]]; // connection request intializes NSURL connection * connection = [[NSURLConnection alloc] initWithRequest: request representative: self]; [Connection start]; } #pragma connection - (void) connection: (NSURLConnection *) connection was receivadata} - (zero) connection -Definition loading: (NSURLConnection *) connection {serverResponse = [[NSString alloc] initWithData: response encoding: NSUTF8StringEncoding]; NSRL session with representatives instead of NSURL Connection (to simplify the process):    

< pre> [[[NSURL session sharing session] Dataset with request: Request complete handler: ^ (NSDT * data, NSRRSpons * response, NSERR * error) {if (error and amp; data) If necessary, then also. Check Response.statusCode * Server Display = [[NSString Alloc] initWithData: Data Encoding: NSUTF8StringEncoding]; Dispatches_assink (sending_out_man_q ()), {{full (server rps);}); } Else {dispatch_async (dispatch_get_main_queue), ^ {full (zero); // show some warning about a connection etc.}}}}}] bio data];

Complete

  - (zero) login: (NSString *) Username: Password (NSString *) Password Complete: (Zero (^   

and then Log in ViewController's response to completion

  [user login: @ "AAA" password: @ "BBB" closing: ^ (NSString * response) {If ([feedback is eclotostry Sang: @ "CCC"]) {// Success!} Else {// Warning}};    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -