【发布时间】:2019-02-18 10:15:24
【问题描述】:
我正在研究是否可以在 WKWebView 中嵌入 Apple Pay JS/Web Payments API。我们有一个嵌入在 WKWebView 中的网络应用程序,我们希望通过 JavaScript 实现 Apple Pay,而无需桥接。
我整理了一个非常基本的ViewController.swift 示例如下,利用Apple Pay on the Web Demo
import UIKit
import WebKit
class ViewController: UIViewController, WKUIDelegate {
var webView: WKWebView!
override func loadView() {
let webConfiguration = WKWebViewConfiguration()
webView = WKWebView(frame: .zero, configuration: webConfiguration)
webView.uiDelegate = self
view = webView
}
override func viewDidLoad() {
super.viewDidLoad()
let myURL = URL(string:"https://applepaydemo.apple.com")
let myRequest = URLRequest(url: myURL!)
webView.load(myRequest)
}
}
呈现了 Apple Pay 按钮,但也显示了不支持的设备的错误消息(见下文),并且无法单击该按钮。
我认为这意味着在这种情况下没有支持。我再次尝试使用SFSafariViewController 并显示按钮并在点击时启动Apple Pay。简而言之 - 一切都很完美。
import UIKit
import SafariServices
class ViewController: UIViewController, SFSafariViewControllerDelegate {
override func viewDidAppear(_ animated: Bool) {
let safariVC = SFSafariViewController(url: URL(string:"https://applepaydemo.apple.com")!)
self.present(safariVC, animated: false, completion: nil)
}
}
我想知道的是,我如何为 WkWebView 实现此功能是否存在问题,或者是否存在错误。看起来按钮出现或按钮不起作用都是错误。显然在一个层面上它认为 WkWebView 是兼容的,但在另一个层面上却不是。这似乎是一个需要报告的错误,但我对 Swift 还很陌生,所以这可能是一个实现问题。
谢谢!
【问题讨论】:
标签: ios swift wkwebview applepay sfsafariviewcontroller