aje*_*rma 6 ios passkit swift applepay
我已经使用 Passkit 框架在我的 iOS 应用程序中实现了 Apple Pay。我做了所有 这些事情来设置 Apple Pay。我正在使用沙箱帐户。我在钱包应用程序中添加了卡片,这些卡片是我从这个链接复制的测试卡片。我正在使用的这段代码:
print("\(((self.grandTotalLabel.text!).replacingOccurrences(of: "$", with: "")))")
let paymentNetworks = [PKPaymentNetwork.amex]
if PKPaymentAuthorizationViewController.canMakePayments(usingNetworks: paymentNetworks){
paymentRequest.supportedNetworks = paymentNetworks
paymentRequest.merchantCapabilities = .capability3DS
paymentRequest.requiredShippingAddressFields = [.all]
paymentRequest.paymentSummaryItems = self.itemToSell(shipping: 10.0)
let sameDayShipping = PKShippingMethod(label: "Same day divilery", amount: 12.99)
sameDayShipping.detail = "Same day divilery Detail"
sameDayShipping.identifier = "sameDay"
let twDaysShipping = PKShippingMethod(label: "Two days divilery", amount: 4.99)
twDaysShipping.detail = "Two days divilery Detail"
twDaysShipping.identifier = "twoDays"
let freeShipping = PKShippingMethod(label: "Free shipping divilery", amount: 0.0)
freeShipping.detail = "Free shipping divilery Detail"
freeShipping.identifier = "freeShipping"
// paymentRequest.shippingMethods = [sameDayShipping,twDaysShipping, freeShipping]
let applePayVC = PKPaymentAuthorizationViewController(paymentRequest: paymentRequest)
applePayVC?.delegate = self
self.present(applePayVC!, animated: true) {
print("ApplePayViewcontroller")
}
}
else{
print("Please set up for apple pay")
}
func itemToSell(shipping:Float) -> [PKPaymentSummaryItem]{
print(Double("\(((self.grandTotalLabel.text!).replacingOccurrences(of: "$", with: "")))") as Any)
let dishItems = PKPaymentSummaryItem(label: "FoodKonnect", amount: NSDecimalNumber(string: "21.00"))
let discount = PKPaymentSummaryItem(label: "Discount", amount: 1.0)
let shipping = PKPaymentSummaryItem(label: "Shipping", amount: NSDecimalNumber(string: "\(shipping)"))
let totalAmount = dishItems.amount.adding(discount.amount)
let totalPrice = PKPaymentSummaryItem(label: "FoodKonnect application", amount: totalAmount)
return [dishItems, discount,shipping, totalPrice]
}
Run Code Online (Sandbox Code Playgroud)
这些我使用的所有代表 PKPaymentAuthorizationViewControllerDelegate:
extension CartViewController:PKPaymentAuthorizationViewControllerDelegate{
func paymentAuthorizationViewControllerDidFinish(_ controller: PKPaymentAuthorizationViewController) {
controller.dismiss(animated: true, completion: nil)
}
// @available(iOS 11.0, *)
func paymentAuthorizationViewController(_ controller: PKPaymentAuthorizationViewController, didSelectShippingContact contact: PKContact, completion: @escaping (PKPaymentAuthorizationStatus, [PKShippingMethod], [PKPaymentSummaryItem]) -> Void) {
print("\(#function)")
}
@available(iOS 11.0, *)
func paymentAuthorizationViewController(_ controller: PKPaymentAuthorizationViewController, didSelect shippingMethod: PKShippingMethod, handler completion: @escaping (PKPaymentRequestShippingMethodUpdate) -> Void) {
print("\(#function)")
}
@available(iOS 11.0, *)
func paymentAuthorizationViewController(_ controller: PKPaymentAuthorizationViewController, didAuthorizePayment payment: PKPayment, handler completion: @escaping (PKPaymentAuthorizationResult) -> Void) {
print("\(#function)")
}
}
Run Code Online (Sandbox Code Playgroud)
Apple pay viewcontroller 正在显示,此屏幕显示处理圆视图。
但几秒钟后,我收到此错误消息:
小智 8
在每个实现的PKPaymentAuthorizationViewControllerDelegate具有completion/ 的委托函数中, handler您必须使用适当的参数调用该块,最重要的是使用适当的状态。
在 iOS 11 上(大约)15-20 秒内未调用该块,iOS 正在终止付款并显示您所看到的错误。在 iOS 10 上,它会让你Processing无限期地旋转,直到completion块被调用。
我遇到了同样的问题,结果发现handler在一种边缘情况下我根本没有调用该块。
| 归档时间: |
|
| 查看次数: |
4446 次 |
| 最近记录: |