17

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

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

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

4

4 回答 4

14

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

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

于 2017-07-19T01:35:01.743 回答
8

由于系统的安全性,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];
}
于 2017-07-19T14:28:42.450 回答
8

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

查看今年的会议了解更多详情。

于 2017-07-20T13:30:46.313 回答
0

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

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

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

避免在操作表中启用滚动。如果操作表有太多选项,人们必须滚动查看所有选项。滚动需要额外的时间来做出选择,并且很难在不无意中点击按钮的情况下进行。

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

于 2017-07-25T09:24:54.723 回答