1

I am developing an iOS application to scan vin numbers. I am able to successfully scan the vin number. I wish to pass this vin number to a website "http://tk14.webng.com/bswbhtml.html". There will be a text field here. After I click a button in the application it should be copied to the text field automatically.

The code is as follows

- (IBAction)sendVIN:(id)sender
{  
     _resultField.text = vin;
}

I got the vin number in the variable vin. This has to be automatically copied to that text field.

How can I do this?

Shekhar Gupta
  • 6,206
  • 3
  • 30
  • 50
user2541457
  • 71
  • 1
  • 8
  • Why not send a POST request to that URL including your VIN number as a POST parameters. I do assume you have access to that page and can modify the source file to include a Javascript to check for and set the VIN POST paramater into the text field. Here's a link on how to get POST parameters using Javascript: http://stackoverflow.com/questions/1961069/getting-value-get-or-post-variable-using-javascript – Zhang Aug 12 '13 at 12:07

1 Answers1

1

You need to modify the html for the input field on your webpage, adding a "value" property:

 <input value="vin number goes here" />

There are a couple of ways you could achieve this. The best way would be to load the webpage via NSURLConnection, instead of your via your webview, amend the HTML, and then ask the webview to load the amended HTML. Here's an example:

int vinNumber = 1234567890;

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://tk14.webng.com/bswbhtml.html"]];

[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue currentQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {


    if (error == nil && data != nil)
    {

        NSString *html = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

        if ([html rangeOfString:@"<input type=\"text\" name=\"vinnumber\">"].location != NSNotFound)
        {

            NSString *amendedInput = [NSString stringWithFormat:@"<input type=\"text\" name=\"vinnumber\" value=\"%i\">", vinNumber];
            NSString *amendedHTML = [html stringByReplacingOccurrencesOfString:@"<input type=\"text\" name=\"vinnumber\">" withString:amendedInput];
            [_webview loadHTMLString:amendedHTML baseURL:[NSURL URLWithString:@"http://tk14.webng.com/bswbhtml.html"]];

        }


    }


}];

The resulting page looks like this on my iPhone 4S:

enter image description here

petemorris
  • 516
  • 4
  • 4