如何在Apple Pay PKPaymentAuthorizationViewController上方显示UIAlertView?

CTL*_*CTL 17 objective-c ios applepay

使用下面的标准UIAlertView代码将在Apple Pay PKPaymentAuthorizationViewController表下方显示警报.

[[[UIAlertView alloc] initWithTitle:@"Payment Error"
                            message:[error localizedDescription]
                           delegate:nil
                  cancelButtonTitle:@"Okay"
                  otherButtonTitles:nil] show];
Run Code Online (Sandbox Code Playgroud)

如何在付款授权书上方显示?或者是否有不同的方式为Apple Pay显示错误消息?我想在用户输入无效的送货地址时给出特定的错误消息.

kli*_*ger 10

您无法在任何UI元素之上显示UI元素,Remote View Controllers因为它可能会危及系统的安全性.这包括PKPaymentAuthorizationViewController.

在此处阅读有关远程视图控制器的更多信


Nik*_*iya 8

你可以不显示UIAlertViewPKPaymentAuthorizationViewController系统的安全性,因为.

整个UI PKPaymentAuthorizationViewController通过远程视图控制器呈现.这意味着在您给出的PKPaymentRequest之外,不可能以其他方式设置或修改此视图的内容.

而对于处理Apple Pay错误,您必须使用PKPaymentAuthorizationViewControllerDelegate委托方法来显示付款已成功完成或有任何错误.

对于show PKPaymentAuthorizationViewController,目前的付款视图控制器为:

PKPaymentAuthorizationViewController *paymentVC = [[PKPaymentAuthorizationViewController alloc] initWithPaymentRequest:request];
paymentVC.delegate = self;
[self presentViewController:paymentVC animated:true completion:nil];
Run Code Online (Sandbox Code Playgroud)
  • 客户使用Touch ID批准购买(或者,如果失败3次,则输入他们的密码).
  • 指纹图标变成一个微调器,标签为"处理"
  • 您的代理人收到paymentAuthorizationViewController(_:didAuthorizePayment:completion :)回调
  • 您的应用程序与您的支付处理器和网站后端异步通信,以实际收取这些付款详细信息.完成后,根据结果调用您作为参数使用PKPaymentAuthorizationStatus.success或PKPaymentAuthorizationStatus.failure的完成处理程序.
  • PKPaymentAuthorizationViewController微调器动画成成功或失败图标.如果成功,将从PassBook收到通知,指示客户信用卡上的费用.
  • 您的代理人收到paymentAuthorizationViewControllerDidFinish(_ :)回调.然后它负责调用dismiss(动画:完成:)以关闭付款屏幕.

错误屏幕

错误屏幕

- (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];
}
Run Code Online (Sandbox Code Playgroud)


pes*_*sch 7

在iOS 11中有一个新的回调

public func paymentAuthorizationController(_ controller: PKPaymentAuthorizationController, didAuthorizePayment payment: PKPayment,
handler completion: (PKPaymentAuthorizationResult) -> Void)
Run Code Online (Sandbox Code Playgroud)

如您所见,处理程序从中更改

completion: (PKPaymentAuthorizationStatus) -> Void)
Run Code Online (Sandbox Code Playgroud)

handler completion: (PKPaymentAuthorizationResult) -> Void)
Run Code Online (Sandbox Code Playgroud)

从iOS 11开始,我们将在完成处理程序中获得一个status数组NSErrors.

有关详细信息,请查看今年的会议.