Web サービスに関連する登録およびログイン フォームを作成する必要があります。登録の詳細を Web サービスに送信するにはどうすればよいですか? また、Web サービスからユーザー名とパスワードを使用してログインするにはどうすればよいですか? 助けて。
質問する
2358 次
2 に答える
0
登録フォームの場合:
簡単な XML 解析を行う必要があります。リンクを実行し、登録時にユーザーが入力するデータを渡し、XML 解析を介してそのデータを Web サービスに送信する必要があります。
于 2012-12-17T10:40:27.207 に答える
0
この記事では、iPhone アプリケーション内から XML Web サービスと通信する方法を十分に理解できるようにし、例を使用して、独自のプロジェクトで他の Web サービスを使用するための強固な基盤を提供します。
http://www.allappsdevelopers.com/TopicDetail.aspx?TopicID=97963e2d-37a5-4e48-b434-3fced80d2b55
例:
-(UITextField*) customTextfield:(NSString*)fieldType textName:(NSString*)str initFrame:(CGRect)frame
{
UITextField *customField = [[UITextField alloc] initWithFrame:frame];
customField.delegate = self;
customField.adjustsFontSizeToFitWidth = NO;
customField.borderStyle = UITextBorderStyleRoundedRect;
customField.textColor = [UIColor blackColor];
customField.clearButtonMode = UITextFieldViewModeWhileEditing;
customField.clearsOnBeginEditing = NO;
customField.autocapitalizationType = UITextAutocapitalizationTypeNone;
customField.autocorrectionType = UITextAutocorrectionTypeNo;
customField.enablesReturnKeyAutomatically = YES;
customField.returnKeyType = UIReturnKeyDefault;
customField.placeholder = NSLocalizedString(str, nil);
customField.keyboardType = UIKeyboardTypeDefault;
return customField;
}
- (void)viewDidLoad
{
txtfname = [self customTextfield:@"" textName:@"" initFrame:CGRectMake(120, 75, 160, 30)];
[self.view addSubview:txtfname];
txtlastname = [self customTextfield:@"" textName:@"" initFrame:CGRectMake(120, 115, 160, 30)];
[self.view addSubview:txtlastname];
txtemail = [self customTextfield:@"" textName:@"" initFrame:CGRectMake(120, 155, 160, 30)];
[self.view addSubview:txtemail];
txtpwd = [self customTextfield:@"" textName:@"" initFrame:CGRectMake(120, 195, 160, 30)];
txtpwd.secureTextEntry=YES;
[self.view addSubview:txtpwd];
txtRePwd= [self customTextfield:@"" textName:@"" initFrame:CGRectMake(120, 235, 160, 30)];
txtRePwd.secureTextEntry=YES;
[self.view addSubview:txtRePwd];
}
フォーム送信時
-(void) fieldValidate
{
NSString *emailRegEx =@"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
NSPredicate *regExpred =[NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegEx];
BOOL myStringCheck = [regExpred evaluateWithObject:txtemail.text];
if ([txtfname.text length]==0) {
[self callAlert:@"Please Enter First Name"];
[txtfname becomeFirstResponder];
return;
}
else if ([txtlastname.text length]==0) {
[self callAlert:@"Please Enter Last Name"];
[txtlastname becomeFirstResponder];
return;
}
else if(!myStringCheck){
[self callAlert:@"Email address should be in yourname@domainname.com format"];
[txtemail becomeFirstResponder];
return;
}
else if ([txtpwd.text length]==0) {
[self callAlert:@"Password should have atleast 1 characters"];
[txtpwd becomeFirstResponder];
return;
}
else if ([txtRePwd.text length]==0) {
[self callAlert:@"Password should have atleast 1 characters"];
// [txtRePwd becomeFirstResponder];
return;
}
else if (![txtpwd.text isEqualToString:txtRePwd.text])
{
[self callAlert:@"Password And Repassword Mismatched"];
[txtpwd becomeFirstResponder];
return;
}
[txtfname resignFirstResponder];
[txtlastname resignFirstResponder];
[txtemail resignFirstResponder];
[txtpwd resignFirstResponder];
[txtRePwd resignFirstResponder];
NSString *Restrqst = [NSString stringWithFormat:@"<user>\n"
"<account_attributes><first_name>%@</first_name></account_attributes>\n"
"<lastName>%@</lastName>\n"
"<email>%@</email>\n"
"<password>%@</password>\n"
"<password_confirmation>%@</password_confirmation>\n"
"</user>\n",txtfname.text,txtlastname.text,txtemail.text,txtpwd.text];
NSURL *RestURL = [NSURL URLWithString:@"www.xxxx.com/signup"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:RestURL];
[request setDelegate:self];
request.shouldPresentCredentialsBeforeChallenge = YES ;
[request addRequestHeader:@"Content-Type" value:@"application/xml"];
[request appendPostData:[Restrqst dataUsingEncoding:NSUTF8StringEncoding]];
[request setRequestMethod:@"POST"];
[request setDidFinishSelector:@selector(requestDone:)];
[request setDidFailSelector:@selector(requestWentWrong:)];
[request startAsynchronous];
}
于 2012-12-17T10:42:48.267 に答える