简体   繁体   English

PKPaymentAuthorizationViewController 不调用委托

[英]PKPaymentAuthorizationViewController not calling delegate

I've set up a PKPaymentAuthorizationViewController with a valid PKPaymentRequest, logged in an account from the Sandbox with a valid test card and shipping address .我已经使用有效的 PKPaymentRequest 设置了一个 PKPaymentAuthorizationViewController,并使用有效的测试卡和送货地址从沙箱登录了一个帐户。 I've changed the region to USA, but nothing changed.我已将地区更改为美国,但没有任何变化。 The app has all the valid certificates and entitilements.该应用程序具有所有有效的证书和权利。

func getApplePayController(request: PKPaymentRequest) -> PKPaymentAuthorizationViewController? {
            guard let vc = PKPaymentAuthorizationViewController(paymentRequest: request) else {
                return nil
            }

            //Set ourselves as delegate to get callbacks on the transaction status
            vc.delegate = self

            //we keep a weak reference to the controller to be able to dismiss it if necessary
            self.applePayViewController = vc//This is weak

            return vc
        }

And to present:并介绍:

//Show Apple Pay screen with configured PKPaymentRequest object
        guard let vc = getApplePayController(request: paymentRequest) else {
            dLog("Error instantiating Apple Pay screen")
            handleEventType(.status(.failed))
            return
        }

        assert(delegate != nil)
        assert(applePay.didAuthorize == false)
        assert(vc.delegate != nil)

        //disable swipe to dismiss
        if #available(iOS 13.0, *) {
            vc.isModalInPresentation = true
        }

        if var topController = UIApplication.shared.keyWindow?.rootViewController {
            while let presentedViewController = topController.presentedViewController {
                topController = presentedViewController
            }

            // topController should now be your topmost view controller
            topController.present(vc, animated: true, completion: nil)
        }

The screen shows up, if I click on cancel everything freezes.屏幕出现,如果我点击取消,一切都会冻结。 If I click on the background the screen gets automatically dismissed, but the rest of the view is not interactive (PKPaymentAuthorizationViewController is not dismissed, but its ui is hidden).如果我点击背景,屏幕会自动关闭,但视图的其余部分不是交互式的(PKPaymentAuthorizationViewController 没有关闭,但它的 ui 被隐藏)。 If I click on Pay it asks for the pin and it's stuck processing.如果我点击“支付”,它会要求输入密码,但它会卡住处理。 No delegate is called in either case.在任何一种情况下都不会调用委托。

My implementation:我的实现:

public func paymentAuthorizationViewControllerDidFinish(_ controller: PKPaymentAuthorizationViewController) {
print("Dismiss")
}

public func paymentAuthorizationViewController(_ controller: PKPaymentAuthorizationViewController,
                                 didAuthorizePayment payment: PKPayment,
                                                  completion: @escaping (PKPaymentAuthorizationStatus) -> Void) {
           completion(.success)
           return;
}

@available(iOS 11.0, *)
        public func paymentAuthorizationViewController(_ controller: PKPaymentAuthorizationViewController,
                                 didAuthorizePayment payment: PKPayment,
                                                     handler: @escaping (PKPaymentAuthorizationResult) -> Void) {
            handler(PKPaymentAuthorizationResult(status: .success, errors: nil))
           return;
}

Not one of the three methods is ever called, no matter what I do.无论我做什么,都不会调用这三种方法中的任何一种。 I've checked and the delegate is set up correctly.我已经检查过并且委托设置正确。

Any idea?任何的想法?

I now implemented also PKPaymentAuthorizationControllerDelegate even though I' not using it and it works...我现在也实现了 PKPaymentAuthorizationControllerDelegate 即使我没有使用它并且它可以工作......

    public func paymentAuthorizationControllerDidFinish(_ controller: PKPaymentAuthorizationController) {
    return
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM