【发布时间】:2020-02-03 10:02:23
【问题描述】:
我已经使用有效的 PKPaymentRequest 设置了一个 PKPaymentAuthorizationViewController,使用有效的测试卡和shipping address 从沙盒登录了一个帐户。我已将地区更改为美国,但没有任何改变。该应用程序具有所有有效的证书和权利。
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
}
并呈现:
//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)
}
屏幕出现,如果我点击取消,一切都会冻结。如果我单击背景,屏幕会自动关闭,但视图的其余部分不是交互式的(PKPaymentAuthorizationViewController 不会关闭,但它的 ui 是隐藏的)。如果我点击支付,它会要求输入密码并且它会卡住处理。在这两种情况下都不会调用委托。
我的实现:
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;
}
无论我做什么,都不会调用这三种方法中的任何一种。我已经检查过了,委托设置正确。
有什么想法吗?
【问题讨论】:
-
展示你如何呈现和分配
PKPaymentAuthorizationViewController的代表 -
我也有这个问题,但只在模拟器上,假设它是一个错误并继续前进,看看是否有修复。
-
更新了问题。发生在设备和模拟器上
-
@vale 你明白了吗?也有同样的经历
-
是的,我用对我有用的方法回答了我自己的问题,但考虑到反对意见,它对大多数人不起作用......