I have a registration view controller that processes all user input and calls a function in another class (wsClass) passed to it, this data as NSDictionary.
A function is called in wsClass and a connection is made, and data is returned from the server and available in the session.
My question is how to return this data to the control registration controller, where the function was originally called, it always becomes empty.
Here is the call in registrationViewController:
wsClass *ws = [[wsClass alloc] init]; NSDictionary *testDict = [[NSDictionary alloc] initWithObjectsAndKeys:username.text,@"username",email.text,@"email",password.text,@"password", nil]; NSDictionary *respDict = [ws sendData:testDict];
Here is the function called in wsClass.m:
- (NSDictionary *)sendData:(NSDictionary *)sendDict { NSMutableString *sendStr = [[NSMutableString alloc] init]; [sendDict enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { [sendStr appendFormat:@"&%@=%@", key, obj]; }]; NSLog(@"sendStr is: %@",sendStr); NSString *noteDataString = [NSString stringWithFormat:@"%@%@",REQUIRED,sendStr]; NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration]; NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfiguration]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlTest]]; request.HTTPBody = [noteDataString dataUsingEncoding:NSUTF8StringEncoding]; request.HTTPMethod = @"POST"; NSURLSessionDataTask *postDataTask = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
}
source share