由于系统的安全性,UIAlertView
您无法显示。PKPaymentAuthorizationViewController
整个 UIPKPaymentAuthorizationViewController
通过远程视图控制器呈现。这意味着在您给它的 PKPaymentRequest 之外,不可能以其他方式设置或修改此视图的内容。
对于处理 Apple Pay 错误,您必须使用PKPaymentAuthorizationViewControllerDelegate
委托方法来显示付款成功完成或有任何错误。
对于 show PKPaymentAuthorizationViewController
,将支付视图控制器显示为:
PKPaymentAuthorizationViewController *paymentVC = [[PKPaymentAuthorizationViewController alloc] initWithPaymentRequest:request];
paymentVC.delegate = self;
[self presentViewController:paymentVC animated:true completion:nil];
- 客户使用 Touch ID 批准购买(或者,如果 3 次失败,则输入他们的密码)。
- 指纹图标变成了一个微调器,带有“处理中”标签</li>
- 您的委托接收到 paymentAuthorizationViewController(_:didAuthorizePayment:completion:) 回调
- 您的应用程序与您的支付处理器和网站后端进行异步通信,以实际使用这些支付详细信息进行收费。一旦完成,您将调用作为参数提供的完成处理程序,并根据结果使用 PKPaymentAuthorizationStatus.success 或 PKPaymentAuthorizationStatus.failure。
- PKPaymentAuthorizationViewController 微调器动画成成功或失败图标。如果成功,PassBook 将发出通知,指示客户信用卡上的费用。
- 您的委托接收到 paymentAuthorizationViewControllerDidFinish(_:) 回调。然后它负责调用dismiss(animated:completion:) 来关闭支付屏幕。


- (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller
didAuthorizePayment:(PKPayment *)payment
completion:(void (^)(PKPaymentAuthorizationStatus status))completion {
//=========================================
//=========================================
// Call your api here for charge payment and according to that api result show complition as follow
//========================================
//========================================
// Use your payment processor's SDK to finish charging your customer.
// When this is done, call:
completion(PKPaymentAuthorizationStatusSuccess);
// When this is Payment not completed, call:
// completion(PKPaymentAuthorizationStatusFailure);
// When this is Supplied billing address is insufficient or otherwise invalid, call:
// completion(PKPaymentAuthorizationStatusInvalidBillingPostalAddress);
// When this is Supplied postal address is insufficient or otherwise invalid, call:
// completion(PKPaymentAuthorizationStatusInvalidShippingPostalAddress);
// When this is Supplied contact information is insufficient or otherwise invalid, call:
// completion(PKPaymentAuthorizationStatusInvalidShippingContact);
}
// Sent to the delegate when payment authorization is finished. This may occur when
// the user cancels the request, or after the PKPaymentAuthorizationStatus parameter of the
// paymentAuthorizationViewController:didAuthorizePayment:completion: has been shown to the user.
//
// The delegate is responsible for dismissing the view controller in this method.
- (void)paymentAuthorizationViewControllerDidFinish:(PKPaymentAuthorizationViewController *)controller {
[self dismissViewControllerAnimated:true completion:nil];
}