아이폰어플개발정보2010. 10. 12. 03:58
iMessages,json, ASIHttpRequest 프레임웍이용 사용자정의 form만들기

In this tutorial you will actually learn how to send POST request to the website using the ASIHTTPRequest and you can see a basic usage of the JSON-framework.

Lets start with our xProgress back-office. If you don’t have an account already, register yourself on the server (http://www.xprogress.com/) , go to the My Account section, click on iMessages.

Fill the name of your new form application and setup up to five recipients who will receive data from the form. All the data is stored in the same time in the database than you don’t have to worry about loosing anything if there will be a problem with your email.

Once you have your first form created, you can manage the fields you want to use … click on Manage Fields in the table above the form.

On this page you can manage and reorder the fields you want to have in the form.

Once you have those fields set-up, click the Back button and click on those little gears, just next to the name of your form. This link will take you to the API example page which contains your unique id hash code that has to be included in your code and the example code (same one I’ve used in the example application in this tutorial.

This is the main function that is sending your data:

  1. - (IBAction)sendMessage:(UIButton *)sender {  
  2.     NSURL *urlToSend = [[[NSURL alloc] initWithString: @"http://www.xprogress.com/imessages-send/?code=e179922a111ee2cbb6f09d85e84c8e2d2f026323"] autorelease];  
  3.     ASIFormDataRequest *request = [[[ASIFormDataRequest alloc] initWithURL:urlToSend] autorelease];  
  4.     [request setPostValue:[self.fieldName text] forKey:@"name"];  
  5.     [request setPostValue:[self.fieldSurname text] forKey:@"surname"];  
  6.     [request setPostValue:[self.fieldMail text] forKey:@"email"];  
  7.     [request setPostValue:[self.fieldSubject text] forKey:@"subject"];  
  8.     [request setPostValue:[self.fieldMessage text] forKey:@"message"];  
  9.     [request start];  
  10.     NSError *error = [request error];  
  11.     if (!error) {  
  12.         NSString *response = [request responseString];  
  13.         SBJSON *parser = [[SBJSON alloc] init];  
  14.         NSDictionary *data = [parser objectWithString:response error:nil];  
  15.         [parser release];  
  16.         int result = [[data objectForKey:@"result"] intValue];  
  17.         if (result) self.resultLabel.text = @"Your message has been sent.";  
  18.         else self.resultLabel.text = @"We were unable to send your message!";  
  19.         NSString *error = [data objectForKey:@"error"];  
  20.         if ([error length] > 0) NSLog(@"Error: %@", error);  
  21.     }  
  22. }  

Now you just have to setup all the fields in Interface Builder (IB) and the work is done :) Full example is included and is available for download in the top-right corner of this article.

http://www.xprogress.com/post-46-building-custom-forms-in-your-iphone-app-using-imessages-asihttprequest-and-json-framework/

Posted by 오늘마감

댓글을 달아 주세요