Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/107.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将数据从iOS标签字段发送到网站文本字段_Ios_Objective C_Web Services_Parameter Passing - Fatal编程技术网

将数据从iOS标签字段发送到网站文本字段

将数据从iOS标签字段发送到网站文本字段,ios,objective-c,web-services,parameter-passing,Ios,Objective C,Web Services,Parameter Passing,我正在开发一个iOS应用程序来扫描vin编号。我能够成功扫描vin号。我希望将此vin号传递到网站“”。这里将有一个文本字段。单击应用程序中的按钮后,它应自动复制到文本字段 代码如下 - (IBAction)sendVIN:(id)sender { _resultField.text = vin; } 我在变量vin中获得了vin编号。必须将其自动复制到该文本字段中 如何执行此操作?您需要修改网页上输入字段的html,并添加一个“值”属性: <input value="v

我正在开发一个iOS应用程序来扫描vin编号。我能够成功扫描vin号。我希望将此vin号传递到网站“”。这里将有一个文本字段。单击应用程序中的按钮后,它应自动复制到文本字段

代码如下

- (IBAction)sendVIN:(id)sender
{  
     _resultField.text = vin;
}
我在变量
vin
中获得了vin编号。必须将其自动复制到该文本字段中


如何执行此操作?

您需要修改网页上输入字段的html,并添加一个“值”属性:

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

有几种方法可以实现这一点。最好的方法是通过NSURLConnection加载网页,而不是通过webview修改HTML,然后要求webview加载修改后的HTML。下面是一个例子:

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"]];

        }


    }


}];
int-vinNumber=1234567890;
NSURLRequest*request=[NSURLRequest requestWithURL:[NSURL URLWithString:@]http://tk14.webng.com/bswbhtml.html"]];
[NSURLConnection sendAsynchronousRequest:请求队列:[NSOperationQueue currentQueue]完成处理程序:^(NSURLResponse*响应,NSData*数据,NSError*错误){
如果(错误==nil&&data!=nil)
{
NSString*html=[[NSString alloc]initWithData:数据编码:NSUTF8StringEncoding];
if([html rangeOfString:@”“).location!=NSNotFound)
{
NSString*amendedInput=[NSString stringWithFormat:@',VIN编号];
NSString*amendedHTML=[html StringByReplacingOfString:@”“with String:amendedInput];
[_WebViewLoadHtmlString:AmendedHtmlBaseUrl:[NSURL URLWithString:@”http://tk14.webng.com/bswbhtml.html"]];
}
}
}];
在我的iPhone 4S上,生成的页面如下所示:


您需要修改网页上输入字段的html,添加一个“值”属性:

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

有几种方法可以实现这一点。最好的方法是通过NSURLConnection加载网页,而不是通过webview修改HTML,然后要求webview加载修改后的HTML。下面是一个例子:

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"]];

        }


    }


}];
int-vinNumber=1234567890;
NSURLRequest*request=[NSURLRequest requestWithURL:[NSURL URLWithString:@]http://tk14.webng.com/bswbhtml.html"]];
[NSURLConnection sendAsynchronousRequest:请求队列:[NSOperationQueue currentQueue]完成处理程序:^(NSURLResponse*响应,NSData*数据,NSError*错误){
如果(错误==nil&&data!=nil)
{
NSString*html=[[NSString alloc]initWithData:数据编码:NSUTF8StringEncoding];
if([html rangeOfString:@”“).location!=NSNotFound)
{
NSString*amendedInput=[NSString stringWithFormat:@',VIN编号];
NSString*amendedHTML=[html StringByReplacingOfString:@”“with String:amendedInput];
[_WebViewLoadHtmlString:AmendedHtmlBaseUrl:[NSURL URLWithString:@”http://tk14.webng.com/bswbhtml.html"]];
}
}
}];
在我的iPhone 4S上,生成的页面如下所示:


为什么不向该URL发送POST请求,将您的VIN号作为POST参数。我假设您可以访问该页面,并且可以修改源文件以包含一个Javascript来检查并将VIN POST参数设置到文本字段中。这里有一个关于如何使用Javascript获取POST参数的链接:为什么不向该URL发送POST请求,将您的VIN号作为POST参数。我假设您可以访问该页面,并且可以修改源文件以包含一个Javascript来检查并将VIN POST参数设置到文本字段中。这里有一个关于如何使用Javascript获取POST参数的链接:我正在谷歌浏览器中显示页面。数据必须出现在那里我在谷歌浏览器中显示页面。数据必须出现在那里