【问题标题】:How do you show an UIAlertView above the Apple Pay PKPaymentAuthorizationViewController?如何在 Apple Pay PKPaymentAuthorizationViewController 上方显示 UIAlertView?
【发布时间】:2015-08-16 21:32:36
【问题描述】:

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

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

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

【问题讨论】:

  • 您如何呈现警报?我对applepay不是很了解,但是既然是视图控制器,那你是不是在applepayviewcontroller的视图上呈现alert呢?
  • 不确定您的部署目标。我认为不是showing 一个UIAlertViewpresenting 一个UIAlertController 可能是一个更好的主意。只要您有对要在其上显示警报的UIViewController 的引用,这应该不是问题。

标签: ios objective-c applepay


【解决方案1】:

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

阅读更多关于远程视图控制器here

【讨论】:

    【解决方案2】:

    iOS 11 中有一个新的回调

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

    如您所见,处理程序从

    completion: (PKPaymentAuthorizationStatus) -> Void)
    

    handler completion: (PKPaymentAuthorizationResult) -> Void)
    

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

    查看this year's session了解更多详情。

    【讨论】:

      【解决方案3】:

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

      PKPaymentAuthorizationViewController 的整个 UI 通过远程视图控制器呈现。这意味着在您提供的 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:completion:) 回调
      • 您的应用程序与您的付款异步通信 处理器和网站后端实际向这些收费 付款详情。一旦完成,您将调用完成 您作为参数提供的处理程序 PKPaymentAuthorizationStatus.success 或 PKPaymentAuthorizationStatus.failure 取决于结果。
      • PKPaymentAuthorizationViewController 微调器动画成 成功或失败图标。如果成功,将收到通知 来自 PassBook,表明客户信用卡上的费用。
      • 您的代表收到 paymentAuthorizationViewControllerDidFinish(_:) 回调。就是那时 负责调用dismiss(animated:completion:)来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];
      }
      

      【讨论】:

        【解决方案4】:

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

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

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

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

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

        【讨论】:

          猜你喜欢
          • 2015-09-16
          • 2015-10-10
          • 2021-07-28
          • 1970-01-01
          • 1970-01-01
          • 2021-03-13
          • 2020-01-06
          • 1970-01-01
          • 2017-10-26
          相关资源
          最近更新 更多