Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
TPRegisterController.mの抜けてたonSubmitメソッド 間違ってるかもしれないが。書いた
- (void)onSubmit
{
[SVProgressHUD showWithStatus:NSLocalizedString(@"TPRegistControllerSending", nil) maskType:SVProgressHUDMaskTypeBlack];
// フォーム取得
QEntryElement *email = (QEntryElement *)[self.root elementWithKey:@"email"];
QEntryElement *password = (QEntryElement *)[self.root elementWithKey:@"password"];
QEntryElement *password_confirm = (QEntryElement *)[self.root elementWithKey:@"password_confirm"];
QEntryElement *username = (QEntryElement *)[self.root elementWithKey:@"username"];
if(email.textValue == NULL || password.textValue == NULL || password_confirm.textValue == NULL || username.textValue == NULL ) {
[SVProgressHUD showErrorWithStatus:NSLocalizedString(@"TPRegistControllerNoFormData", nil)];
return;
}
// 通信処理
TravelPhotoAPI *tp_api = [TravelPhotoAPI sharedInstance];
if([tp_api.networkStatus boolValue] == NO){
return;
}
AFHTTPClient *sharedClient = [TravelPhotoAPI sharedClient];
// 投稿用の値
NSDictionary *userDic = @{@"user[email]": email.textValue,
@"user[password]": password.textValue,
// @"user[password_confirm]": password_confirm.textValue,
@"user[password_confirmation]": password_confirm.textValue,
@"user[username]": username.textValue};
NSString *path = [tp_api signUpPath];
NSLog(@"%@",path);
[sharedClient setParameterEncoding:AFFormURLParameterEncoding];
AFJSONRequestOperation *operation = [AFJSONRequestOperation
JSONRequestOperationWithRequest:[sharedClient requestWithMethod:@"POST"
path: path
parameters: userDic]
success:^(NSURLRequest *request, NSHTTPURLResponse *response,id JSON) {
[[NSNotificationCenter defaultCenter] postNotificationName:TPReloadTravels object:self userInfo:nil];
[self.navigationController popToRootViewControllerAnimated:YES];
[SVProgressHUD showSuccessWithStatus:NSLocalizedString(@"TPRegistControllerCreateDone", nil)];
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
NSLog(@"Error: %@", error);
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"エラーが発生しました" message:@"メールアドレスまたはパスワードが間違っています"
delegate:self cancelButtonTitle:@"確認" otherButtonTitles:nil];
[alertView show];
[SVProgressHUD dismiss];
}];
[sharedClient enqueueHTTPRequestOperation:operation];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment