“扫描信用卡”功能和UIWebView或WKWebView

3
我有一个信用卡表单,当在iPhone上的Safari中查看时,显示iOS8功能“扫描信用卡”。它非常好用。用户可以使用他们的iPhone相机扫描他们的信用卡。我通过在输入字段上添加HTML5自动完成标签(cc-number、cc-exp-year、cc-exp-month)来实现这一点。然后Safari自动识别并激活扫描功能。但是我想在我的iOS应用程序中的Web视图中显示此功能。表格显示出来了,但扫描功能没有。这可能吗?
这与 WebView上是否可用扫描信用卡选项?相同。
我想在那里发表评论,但我是新用户,所以不能?

你可以使用Card.IO或BinaryTree库来完成。我不明白为什么你要使用Safari。 - baydi
谢谢,baydi。我知道 Card.IO 和其他能够实现这个功能的库。但是由于公司的安全政策,我不能使用它们。一个解决方案是从应用程序中打开 Safari,然后再切换回应用程序。但是如果可能的话,我们希望在应用程序内使用 Web 视图来完成这个功能。 - roach
寻找相同的内容,但是没有找到任何东西... - Himanshu Garg
1个回答

4

我一直在试验中,但无法在UIWebView或WKWebView中使其工作。源HTML文件是从一个启用https的服务器提供的。当从Safari访问URL时,“自动填充信用卡”会显示出来,但在iOS上嵌入时不会显示出来。很遗憾,我认为UIWebView或WKWebView不支持此功能。

<!DOCTYPE html>
<html>
<head>
        <title>Scan credit card using iOS</title>
        <style type="text/css">
        /*<![CDATA[*/
                   input {height:1.5em;width:95%}
                   input[type="text"] {font-size: 2.5em}
                   body {background-color:lightgray;font-size: 3em;font-family: sans-serif;}
                   #purchase {font-size: 2em;font-weight: bold;height:1.2em}
         /*]]>*/
        </style>
</head>
<body>
        <form action="https://yoursite.com/credit-card-purchase" method="post">
                <label for="nameoncard">Name on Card</label> 
                <input autocomplete="cc-name" id="nameoncard" name="nameoncard" type="text"> 
                <label for="ccnumber">Credit Card Number</label> 
                <input autocomplete="cc-number" id="ccnumber" name="ccnumber" type="text">
                <label for="cc-exp-month">Expiration Month</label> 
                <input autocomplete="cc-exp-month" id="cc-exp-month" name="cc-exp-month" type="text"> 
                <label for="cc-exp-year">Expiration Year</label> 
                <input autocomplete="cc-exp-year" id="cc-exp-year" name="cc-exp-year" type="text"> 
                <label for="cvv2">CVV</label> <input autocomplete="cc-csc" id="cvv2" name="cvv2" type="text">
                <input name="submit" type="submit" value="Submit">
        </form>
</body>
</html>

- (void)viewDidLoad {
    [super viewDidLoad];

    NSURL *nsurl = [NSURL URLWithString:@"https://www.myhttpsserver.co.uk/test.html"];

    BOOL showWKWebView = YES;

    if (showWKWebView) {
        //WKWebView version
        WKWebViewConfiguration *theConfiguration = [[WKWebViewConfiguration alloc] init];
        WKWebView *webView = [[WKWebView alloc] initWithFrame:self.view.frame configuration:theConfiguration];

        NSURLRequest *nsrequest=[NSURLRequest requestWithURL:nsurl];
        [webView loadRequest:nsrequest];
        [self.view addSubview:webView];
    } else {
        //UIWebView version
        UIWebView *webView = [[UIWebView alloc] initWithFrame: self.view.frame];
        webView.delegate = self;

        NSURLRequest *request = [[NSURLRequest alloc] initWithURL:nsurl cachePolicy: NSURLRequestUseProtocolCachePolicy timeoutInterval: 5.0];
        [webView loadRequest:request];
        [self.view addSubview:webView];
    }
}

糟糕。这在2020年仍然是这样吗? - swiftyboi
是的,WKWebview中的自动完成功能会打开安全漏洞,因为缺乏Safari的保护措施。可惜他们还没有针对此问题制定策略。 - FlavorScape

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接