iphoneiosios5

Form in iphone app


I am making an iphone app which requires me to make use of website form to get values into database and which i can query through my iphone app in JSON form.

Now i am thinking that since my website form is having only 5-6 fields to fill up, can i make a form in my iphone app itself? I can then send that form data in JSON format to the webserver. Someone please guide me.


Solution

  • You can send the data to jason by post method.

    -(void)registration:(NSString *)nickName 
      TeamName:(NSString *)teamName
      Age:(NSString *)age
      Nationality:(NSString *)countryName
    
    {   
    NSString *JSON = [NSString stringWithFormat:@"{\"NICKNAME\":\"%@\"",nickName];
    JSON = [JSON stringByAppendingFormat:@",\"TEAM_NAME\":\"%@\"",teamName];
    JSON = [JSON stringByAppendingFormat:@",\"AGE\":\"%@\"",age];
    JSON = [JSON stringByAppendingFormat:@",\"NATIONALITY\":\"%@\"",countryName];
    NSLog(@"%@", JSON);
    
      NSData *postData = [JSON dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];    
      NSString *strURL = [NSString stringWithFormat:@"%@%@", kServerPath, kUserRegisterPath];
    
    NSLog(@"Resgistration URL: %@", strURL);
    
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:strURL] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:120.0];    
    
    [request setHTTPMethod:@"POST"];
    [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
    
    [request setHTTPBody:postData];
    
    NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:request delegate:[WebServices sharedInstance]];
    
    
    if(theConnection) {
        NSLog(@"connection made");
    }
    
    else {
        NSLog(@"theConnection is NULL");
    
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error " message:@"Network not responding"  delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
    }
    
    }
    

    http://iosdevelopertips.com/networking/iphone-json-flickr-tutorial-part-1.html

    iPhone/iOS JSON parsing tutorial

    these links may help you