PKPaymentAuthorizationViewController 总是返回零?
Posted
技术标签:
【中文标题】PKPaymentAuthorizationViewController 总是返回零?【英文标题】:PKPaymentAuthorizationViewController always returns nil? 【发布时间】:2017-08-06 15:42:27 【问题描述】:我正在尝试为我的应用程序设置 Apple Pay,但由于某种原因,PKPaymentViewController 总是返回为零(如果代码中的语句是为了测试这个)?任何想法为什么?
@IBAction func payAction(_ sender: Any)
price = donationAmount.text
print(price)
let request = PKPaymentRequest()
request.merchantIdentifier = applePayMerchantID
request.supportedNetworks = SupportedPaymentNetworks
request.merchantCapabilities = PKMerchantCapability.capability3DS
request.countryCode = "GBR"
request.currencyCode = "GBP"
request.requiredBillingAddressFields = PKAddressField.all
//request.applicationData = "This is a test".dataUsingEncoding(NSUTF8StringEncoding)
let paymentSummary = [PKPaymentSummaryItem(label:"Sponsorship", amount: 10.00)]
request.paymentSummaryItems = paymentSummary
let applePayController: PKPaymentAuthorizationViewController = PKPaymentAuthorizationViewController(paymentRequest: request)
applePayController.delegate = self;
if(applePayController == nil)
print("___")
else
self.present(applePayController, animated: true, completion: nil)
func paymentAuthorizationViewController(_ controller: PKPaymentAuthorizationViewController, didAuthorizePayment payment: PKPayment, completion: @escaping (PKPaymentAuthorizationStatus) -> Void)
completion(PKPaymentAuthorizationStatus.success)
func paymentAuthorizationViewControllerDidFinish(_ controller: PKPaymentAuthorizationViewController)
controller.dismiss(animated: true, completion: nil)
【问题讨论】:
使用此功能canMakePayments(usingNetworks:)
来检查您是否可以付款。并告诉我们结果
使用该函数返回true
您是否在 iPhone 设备上正确配置了 Apple Pay?
是的,一切都设置正确并且工作正常
【参考方案1】:
你用错误的 ISO 配置 countryCode
国家代码
两个字母的 ISO 3166 国家/地区代码。
英国的国家代码是GB
Documentation
【讨论】:
以上是关于PKPaymentAuthorizationViewController 总是返回零?的主要内容,如果未能解决你的问题,请参考以下文章