iOS ApplePay PKPaymentAuthorizationViewController 未出现在 Xcode11/iOS 13
iOS ApplePay PKPaymentAuthorizationViewController not appearing in Xcode11/iOS 13
我们的应用程序已实施 ApplePay 多年。就在最近,我按下按钮触发它,结果发现 PKPaymentAuthorizationViewController
的支付 sheet 没有出现。它不会在沙箱(即模拟器或连接到 Xcode 的设备)环境中向上滑动,但放置断点表明它正在创建成功。我测试这个已经有一段时间了,但我怀疑 Xcode11 或 iOS 13.
有什么变化
我的代码是非常标准的 Apple Pay,但发布在下面。
let item = PKPaymentSummaryItem()
item.label = "Our Label"
let price = NSDecimalNumber(mantissa: UInt64(totalPrice), exponent: -2, isNegative: false)
item.amount = price
items.append(item)
request.paymentSummaryItems = items
if let applePayController = PKPaymentAuthorizationViewController(paymentRequest: request) {
applePayController.delegate = self
present(applePayController, animated: true)
}
我遇到了同样的问题,Apple Pay 在我们的应用程序中突然停止工作。我们也支持这个至少半年了。
使用最新的Xcode(Xcode11.2,Beta 2(11B44)),它似乎又可以工作了。
我猜那是一个 Xcode 错误。尽管它没有在 Xcode 的 Xcode 11.1 or Xcode 11.2 beta 2.
发行说明中列出
我已将您的代码段粘贴到我的应用程序中,该应用程序使用 ApplePay,并且我 运行 在沙盒测试设备上安装了它并启用了 ApplePay,但 ApplePay 按钮不起作用。
我觉得很意外。
当您查看 PKPaymentSummaryItem 的文档时,它只有两个初始化程序:
init(label: String, amount: NSDecimalNumber)
init(label: String, amount: NSDecimalNumber, type:PKPaymentSummaryItemType)
两者都没有默认值,但您正在使用空的初始化程序初始化一个。令人惊讶的是没有错误或警告,它甚至出现在代码完成中。
所以我更改了初始化程序:
let item = PKPaymentSummaryItem(label: "Our Label",
amount: NSDecimalNumber(mantissa: UInt64(totalPrice),
exponent: -2,
isNegative: false))
request.paymentSummaryItems = [items]
if let applePayController = PKPaymentAuthorizationViewController(paymentRequest: request) {
applePayController.delegate = self
present(applePayController, animated: true)
}
并且有效(仅在设备上 - 不适用于模拟器)!
这让我感到奇怪,所以我将您的项目从 let
更改为 var
,它也能正常工作。我仍然会使用记录在案的初始化程序。
如果您的 PKPaymentRequest
使用的商户 ID 未在 mobile.entitlements 中列出,则会发生这种情况。或者,如果 MerchantID 未被您应用的配置文件启用。
视图控制器
PKPaymentRequest *request = [[PKPaymentRequest alloc] init];
request.merchantIdentifier = "com.your.app.merchandId"
mobile.entitlements
<dict>
<key>com.apple.developer.in-app-payments</key>
<array>
<string>com.your.app.merchandId</string>
</array>
</dict>
我们的应用程序已实施 ApplePay 多年。就在最近,我按下按钮触发它,结果发现 PKPaymentAuthorizationViewController
的支付 sheet 没有出现。它不会在沙箱(即模拟器或连接到 Xcode 的设备)环境中向上滑动,但放置断点表明它正在创建成功。我测试这个已经有一段时间了,但我怀疑 Xcode11 或 iOS 13.
我的代码是非常标准的 Apple Pay,但发布在下面。
let item = PKPaymentSummaryItem()
item.label = "Our Label"
let price = NSDecimalNumber(mantissa: UInt64(totalPrice), exponent: -2, isNegative: false)
item.amount = price
items.append(item)
request.paymentSummaryItems = items
if let applePayController = PKPaymentAuthorizationViewController(paymentRequest: request) {
applePayController.delegate = self
present(applePayController, animated: true)
}
我遇到了同样的问题,Apple Pay 在我们的应用程序中突然停止工作。我们也支持这个至少半年了。
使用最新的Xcode(Xcode11.2,Beta 2(11B44)),它似乎又可以工作了。
我猜那是一个 Xcode 错误。尽管它没有在 Xcode 的 Xcode 11.1 or Xcode 11.2 beta 2.
发行说明中列出我已将您的代码段粘贴到我的应用程序中,该应用程序使用 ApplePay,并且我 运行 在沙盒测试设备上安装了它并启用了 ApplePay,但 ApplePay 按钮不起作用。
我觉得很意外。
当您查看 PKPaymentSummaryItem 的文档时,它只有两个初始化程序:
init(label: String, amount: NSDecimalNumber) init(label: String, amount: NSDecimalNumber, type:PKPaymentSummaryItemType)
两者都没有默认值,但您正在使用空的初始化程序初始化一个。令人惊讶的是没有错误或警告,它甚至出现在代码完成中。 所以我更改了初始化程序:
let item = PKPaymentSummaryItem(label: "Our Label",
amount: NSDecimalNumber(mantissa: UInt64(totalPrice),
exponent: -2,
isNegative: false))
request.paymentSummaryItems = [items]
if let applePayController = PKPaymentAuthorizationViewController(paymentRequest: request) {
applePayController.delegate = self
present(applePayController, animated: true)
}
并且有效(仅在设备上 - 不适用于模拟器)!
这让我感到奇怪,所以我将您的项目从 let
更改为 var
,它也能正常工作。我仍然会使用记录在案的初始化程序。
如果您的 PKPaymentRequest
使用的商户 ID 未在 mobile.entitlements 中列出,则会发生这种情况。或者,如果 MerchantID 未被您应用的配置文件启用。
视图控制器
PKPaymentRequest *request = [[PKPaymentRequest alloc] init];
request.merchantIdentifier = "com.your.app.merchandId"
mobile.entitlements
<dict>
<key>com.apple.developer.in-app-payments</key>
<array>
<string>com.your.app.merchandId</string>
</array>
</dict>