简体   繁体   English

如何在 ios 应用程序的 wkwebview 中的 amazon.in 输入字段中自动填写信用卡/借记卡详细信息?

[英]How to autofill credit/debit-card details in inputfield in amazon.in in wkwebview in ios app?

I'm developing iOS app in which there is webview(wkwebview), there will be website loaded in wkwebview like amazon.in I have credit/debit-card details like card-number, exp date, etc. securely stored in my iOS app, i want to populate credit/debit-card details into amazon.in payment page inputfields.我正在开发 iOS 应用程序,其中有 webview(wkwebview),将在 wkwebview 中加载网站,如 amazon.in 我有信用卡/借记卡详细信息,如卡号、到期日期等。安全地存储在我的 iOS 应用程序中,我想将信用卡/借记卡详细信息填充到 amazon.in 支付页面输入字段中。

Default safari browser in iPhone is able to autofill credit/debit cards if saved.如果保存,iPhone 中的默认 safari 浏览器能够自动填充信用卡/借记卡。

Please let me know the solution for the same.请让我知道相同的解决方案。

This is amazon payment page:这是亚马逊支付页面:

亚马逊支付页面截图

class ViewController: UIViewController {
let scriptSource = "document.getElementsByName('addCreditCardNumber')[0].value = '1111 1111 1111 1111'"
    var webConfig: WKWebViewConfiguration {
        get {
            let webCfg = WKWebViewConfiguration()
            let controller = WKUserContentController()
            let pre = WKPreferences()
            pre.javaScriptEnabled = true
            webCfg.preferences = pre
            let script = WKUserScript(source: scriptSource, injectionTime: .atDocumentEnd, forMainFrameOnly: false)
            controller.addUserScript(script)
            webCfg.userContentController = controller
            return webCfg;
        }
    }
lazy var webView: WKWebView = {
       let webView = WKWebView(frame: .zero, configuration: self.webConfig)
       webView.translatesAutoresizingMaskIntoConstraints = false
       return webView
   }()

override func viewDidLoad() {
    super.viewDidLoad()
    self.addWKWebView()
}
private func addWKWebView(){
    self.view.addSubview(webView)
    self.view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|[webView]|", options: [], metrics: nil, views: ["webView": webView]))
    self.view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|[webView]|", options: [], metrics: nil, views: ["webView": webView]))
    webView.load(URLRequest(url: URL(string: "https://www.amazon.in")!))
    webView.uiDelegate = self
    webView.navigationDelegate = self
   }}

You can add a custom UserScript for a page with a WKUserScript -object.您可以使用WKUserScript为页面添加自定义用户脚本。 In it you can use standard JavaScript like document.getElementById("creditcard").defaultValue = "12345";在其中您可以使用标准 JavaScript,例如document.getElementById("creditcard").defaultValue = "12345";

This tutorial should give you an idea of it: https://medium.com/capital-one-tech/javascript-manipulation-on-ios-using-webkit-2b1115e7e405 .本教程应该让您了解它: https://medium.com/capital-one-tech/javascript-manipulation-on-ios-using-webkit-2b1115e7e405 For more info on WKUserScript take a look at the official documentation ( https://developer.apple.com/documentation/webkit/wkuserscript )有关WKUserScript的更多信息,请查看官方文档( https://developer.apple.com/documentation/webkit/wkuserscript

Here is What i was using for append my message in webView:这是我用于 append 我在 webView 中的消息的内容:

   public static func appendNewMessage(chatListWebView : UIWebView,  appendTemplet : String) {
        do {
            let temp = "document.getElementById('message_div').innerHTML +=\"" + appendTemplet + "\""
            print(temp)
            chatListWebView.stringByEvaluatingJavaScript(from: "document.getElementById('message_div').innerHTML +=\"" + appendTemplet + "\"");
    } catch  {
//    JLog.error(appendTemplet);
//    ex.printStackTrace();
    }
    }

You can update it according to you situation, Sorry but i do not have time to edit it您可以根据您的情况更新它,对不起,我没有时间编辑它

Hope it help to you!希望对你有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM