ios - WKWebView 中的 Apple Pay JS
问题描述
我正在研究是否可以在 WKWebView 中嵌入 Apple Pay JS/Web Payments API。我们有一个嵌入在 WKWebView 中的 Web 应用程序,我们希望通过 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 很陌生,所以它可能是一个实现问题。
谢谢!
解决方案
不幸的是,您只能将 ApplePay 与 SFSafariViewController 一起使用;这意味着即使出现 ApplePay 按钮,交易流程也不会让您继续,因为 WkWebview 不支持 ApplePay。
推荐阅读
- c# - ASP.NET Core 3.1 OData PageResult 序列化
- android - 你能告诉我如何添加这个活动吗?
- java - Java 程序无法编译:缺少返回语句
- javascript - 在带有 PKCE 的 OAuth 授权流中使用时,如何在 Azure 应用注册中启用 CORS?
- excel - 如果范围内的单元格不等于空白,则将字符串应用于另一个范围内的单元格
- java - 带有 fcm 的 Android 网页视图
- erlang - 如何在 Erlang 中修复不正确的列表?
- azure-active-directory - 在两个 AD B2C 租户之间共享本地帐户
- mysql - 如何在 laravel 中运行多个查询
- c# - 如何在 Linq 中编写此代码以减少代码?