尝试使用Apple Pay时,iOS模拟器会陷入“使用密码付费”

时间:2015-08-31 23:30:54

标签: ios iphone swift ios-simulator applepay

我正在尝试在我的应用上设置Apple Pay,但目前我还没有iPhone 6。因此,在尝试购买一台模拟器之前,我试图让所有东西都能运行,然后尝试让某人借给我一个。

无论如何,我已经到了实际显示ApplePay视图控制器的地步:

enter image description here

但是,当我点击“使用密码付费”时,没有任何反应,所以我无法继续使用服务器完成测试。

以下是我的代码的相关部分:

class PaymentVC: UIViewController,PKPaymentAuthorizationViewControllerDelegate {

@IBAction func onPaymentSubmit(sender: AnyObject) {
    if PKPaymentAuthorizationViewController.canMakePaymentsUsingNetworks(supportedPaymentNetworks) {
        let applePayMerchantID = "merchant.com.id"

        let request = PKPaymentRequest()
        request.merchantIdentifier = applePayMerchantID
        request.supportedNetworks = supportedPaymentNetworks
        request.merchantCapabilities = PKMerchantCapability.Capability3DS
        request.countryCode = "US"
        request.currencyCode = "USD"
        request.paymentSummaryItems = [
            PKPaymentSummaryItem(label: "Custom Order", amount: NSDecimalNumber(float: total))
        ]
        let applePayController = PKPaymentAuthorizationViewController(paymentRequest: request)
        applePayController.delegate = self
        self.presentViewController(applePayController, animated: true, completion: nil)
    }
}

//MARK: Apple Pay

func paymentAuthorizationViewController(controller: PKPaymentAuthorizationViewController, didAuthorizePayment payment: PKPayment, completion: (PKPaymentAuthorizationStatus) -> Void) {

}

func paymentAuthorizationViewControllerDidFinish(controller: PKPaymentAuthorizationViewController) {
    controller.dismissViewControllerAnimated(true, completion: nil)
}

}

知道可能出现什么问题吗?

1 个答案:

答案 0 :(得分:2)

您需要在paymentAuthorizationViewController中退回付款状态。您将看到委托方法有一个完成处理程序,您必须调用该处理程序以指示您是否能够成功处理付款。