使用下面的标准UIAlertView代码将在Apple Pay PKPaymentAuthorizationViewController 表单下方显示警报。
[[[UIAlertView alloc] initWithTitle:@"Payment Error"
message:[error localizedDescription]
delegate:nil
cancelButtonTitle:@"Okay"
otherButtonTitles:nil] show];
如何在付款授权书上方显示?或者是否有不同的方式为Apple Pay显示错误消息?我想在用户输入无效的送货地址时给出具体的错误消息。
答案 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];
- (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常量。