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

时间:2015-06-02 21:42:44

标签: ios objective-c applepay

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

[[[UIAlertView alloc] initWithTitle:@"Payment Error"
                            message:[error localizedDescription]
                           delegate:nil
                  cancelButtonTitle:@"Okay"
                  otherButtonTitles:nil] show];

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

4 个答案:

答案 0 :(得分:10)

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

详细了解远程视图控制器here

答案 1 :(得分:8)

由于系统的安全性,您无法在UIAlertView上显示PKPaymentAuthorizationViewController

PKPaymentAuthorizationViewController的整个用户界面是通过远程视图控制器呈现的。这意味着在您提供的PKPaymentRequest之外,不可能以其他方式设置或修改此视图的内容。

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

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

PKPaymentAuthorizationViewController *paymentVC = [[PKPaymentAuthorizationViewController alloc] initWithPaymentRequest:request];
paymentVC.delegate = self;
[self presentViewController:paymentVC animated:true completion:nil];
  • 客户使用Touch ID批准购买(或者,如果失败,则批准购买) 3次,输入密码)。
  • 指纹图标变为微调器,标签为“处理”
  • 你的代表收到了 paymentAuthorizationViewController(_:didAuthorizePayment:完成:) 回调
  • 您的应用与您的付款异步通信 处理器和网站后端实际上与那些收费 付款详情。完成后,您将调用完成 处理程序,您作为参数给出 PKPaymentAuthorizationStatus.success或 PKPaymentAuthorizationStatus.failure取决于结果。
  • PKPaymentAuthorizationViewController微调器动画为a 成功或失败的图标。如果成功,将收到通知 来自PassBook,显示客户信用卡上的费用。
  • 你的代表收到了 paymentAuthorizationViewControllerDidFinish(_ :)回调。就是这样 负责调用dismiss(动画:完成:)来解雇 付款界面。

Error Screen

Error Screen

- (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];
}

答案 2 :(得分:7)

iOS 11中有一个新的回调

public func paymentAuthorizationController(_ controller: PKPaymentAuthorizationController, didAuthorizePayment payment: PKPayment,
handler completion: (PKPaymentAuthorizationResult) -> Void)

如您所见,处理程序从

更改
completion: (PKPaymentAuthorizationStatus) -> Void)

handler completion: (PKPaymentAuthorizationResult) -> Void)

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

有关详细信息,请查看this year's session

答案 3 :(得分:0)

操作表是响应控件或操作而显示的特定警报样式,并显示与当前上下文相关的一组两个或更多选项。使用操作表让人们在执行潜在的破坏性操作之前启动任务或请求确认。在较小的屏幕上,操作表从屏幕底部向上滑动。在较大的屏幕上,操作表一下子显示为一个弹出窗口。

如果增加清晰度,请提供“取消”按钮。当用户放弃任务时,“取消”按钮会增加信心。取消按钮应始终包含在屏幕底部的操作表中。

使破坏性选择变得突出。对执行破坏性或危险操作的按钮使用红色,并在操作表的顶部显示这些按钮。

避免在操作表中启用滚动。如果操作表有太多选项,人们必须滚动才能看到所有选项。滚动需要额外的时间来做出选择,如果不小心点击按钮就很难做到。

有关开发者指南,请参阅UIAlertControllerStyleActionSheet中的UIAlertController常量。