【问题标题】:"scan credit card" feature and UIWebView or WKWebView“扫描信用卡”功能和 UIWebView 或 WKWebView
【发布时间】:2015-12-05 06:45:34
【问题描述】:

我有一张信用卡表格,在我的 iPhone 上的 Safari 中查看时显示 iOS8 功能“扫描信用卡”。它工作得很好。用户可以使用 iPhone 上的摄像头扫描他们的信用卡。我通过在输入字段上添加 HTML5 自动完成标签(cc-number、cc-exp-year、cc-exp-month)来实现这一点。然后 Safari 会自动识别并激活扫描功能。但是我想在我的 iOS 应用程序中的 web 视图中显示它。表格显示,但扫描功能不显示。这可能吗?

这是同一个问题:Is the Scan Credit Card option available on the WebView?

我想在那里发表评论,但我是新用户,所以我不能?

【问题讨论】:

  • 您可以使用 Card.IO 或 BinaryTree 库来完成。恐怕你为什么要使用 safari
  • 谢谢你。我知道 Card.IO 和其他实现这一点的库。但是由于我们公司的安全政策,我不能使用它们。一种解决方案是从应用程序中打开 safari,然后再切换回应用程序。但如果可能的话,我们希望在应用程序内的 Web 视图中执行此操作。
  • 寻找相同但没有找到任何东西...

标签: ios safari uiwebview wkwebview


【解决方案1】:

我一直在试验,但无法在 UIWebView 或 WKWebView 中完成这项工作。源 html 文件是从启用了 https 的服务器提供的。从 Safari 访问 URL 时会显示“AutoFill Credit Card”,但嵌入 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年还是这样吗?
  • 是的,WKWebview 中的自动完成功能会在没有 Safari 保护的情况下打开安全漏洞。可惜他们没有为此制定策略。
猜你喜欢
  • 1970-01-01
  • 2018-03-06
  • 1970-01-01
  • 2015-11-09
  • 2018-09-17
  • 2019-01-04
  • 1970-01-01
  • 2017-11-25
  • 2020-03-26
相关资源
最近更新 更多