我正在开发 iOS 应用程序,其中有 webview(wkwebview),wkwebview 中会加载网站,如 amazon.in 我有信用卡/借记卡详细信息,如卡号、exp 日期等。安全地存储在我的 iOS 应用程序中,我想将信用卡/借记卡详细信息填充到 amazon.in 付款页面输入字段中。
如果保存,iPhone 中的默认 safari 浏览器能够自动填充信用卡/借记卡。
请让我知道相同的解决方案。
这是亚马逊支付页面:
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
}}
宝慕林4294392
白板的微信
相关分类