确定 Web 客户端支持哪个 Apple Pay Web SDK 版本的好方法是什么?
在检查文档时只发现supportsVersion(number): boolean
除了迭代所有版本,直到找到一个可行的版本之外,没有其他方法。
static getLatestSupportedVersion(): number {
if (!this.doesBrowserSupport()) {
return 0
}
// https://developer.apple.com/documentation/apple_pay_on_the_web/apple_pay_on_the_web_version_history
const LATEST_VERSION = 16
let applePayVersion = LATEST_VERSION
while (!this.supportsVersion(applePayVersion) && applePayVersion > 1) {
--applePayVersion
}
return applePayVersion
}
static supportsVersion(number): boolean {
return window.ApplePaySession.supportsVersion(number)
}
static doesBrowserSupport(): boolean {
if (window["ApplePaySession"]) {
return true
}
return false
}