#objective-c #post #afhttpsessionmanager
#objective-c #Публикация #afhttpsessionmanager
Вопрос:
Я продолжаю получать эту ошибку «результат == сбой ————-«
В NSLog говорится
email = test;
firstname = "<UITextField: 0x7ffe7be159b0; frame = (184 71; 132 30); text = 'test'; clipsToBounds = YES; opaque = NO; autoresize = RM BM; gestureRecognizers = <NSArray: 0x600000248340>; layer = <CALayer: 0x60800003c1e0>>";
lastname = "<UITextField: 0x7ffe7bc0d440; frame = (184 144; 132 30); text = 'test'; clipsToBounds = YES; opaque = NO; autoresize = RM BM; gestureRecognizers = <NSArray: 0x600000248b50>; layer = <CALayer: 0x6000000384c0>>";
password = test;
Я пытаюсь зарегистрировать имя пользователя, фамилию, адрес электронной почты и пароль для доступа к веб-сайту из class.
Вот мой код для регистрации:
(IBAction)createAcct:(id)sender {
if ([self.firstName.text isEqualToString:@""] || [self.lastName.text isEqualToString:@""] || [self.emailtxt.text isEqualToString:@""] || [self.passwordTxt.text isEqualToString:@""]){
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Dont leave text feild blank!" delegate:self cancelButtonTitle:@"done" otherButtonTitles:nil];
[alert show];
}
NSDictionary *parameters = @{@"email": [NSString stringWithFormat:@"%@", _emailtxt.text], @"password": [NSString stringWithFormat:@"%@", _passwordTxt.text], @"firstname" : [NSString stringWithFormat:@"%@", _firstName], @"lastname" : [NSString stringWithFormat: @"%@", _lastName]};
NSLog(@"%@", parameters);
AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc]initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
[manager setRequestSerializer:[AFHTTPRequestSerializer serializer]];
[manager setResponseSerializer:[AFJSONResponseSerializer serializer]];
[manager POST:@"http://www.tageninformatics.com/client/jwu/csis3070_assignment3/user/register/" parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject){
NSLog(@"success");
NSDictionary *data = responseObject;
NSString *dataString = [NSString stringWithFormat:@"%@", [data objectForKey:@"result"]];
NSLog(@"result == %@ -------------", dataString);
if ([dataString isEqualToString:@"success"]){
[[NSUserDefaults standardUserDefaults] setObject:dataString forKey:@"success"];
[[NSUserDefaults standardUserDefaults] synchronize];
NSLog(@"%@", dataString);
//store the token
} else {
//error for storing the token
}
}
failure:^(NSURLSessionDataTask * task, NSError * error) {
NSLog(@"error: %@", error);
}];
}
Ответ №1:
NSDictionary *parameters = @{@"email": [NSString stringWithFormat:@"%@", _emailtxt.text], @"password": [NSString stringWithFormat:@"%@", _passwordTxt.text], @"firstname" : [NSString stringWithFormat:@"%@", _firstName], @"lastname" : [NSString stringWithFormat: @"%@", _lastName]};
NSLog(@"%@", parameters);
изменить _firstName
на _firstName.text
измените _lastName
на _lastName.text
и повторите попытку