我在课堂上创建了一个扩展,以符合协议' STPPaymentContextDelegate'。出于某种原因,编译器抱怨,即使我在扩展中的所有方法都像这样正确地声明。
extension PaymentPopupViewController: STPPaymentContextDelegate {
func paymentContext(_ paymentContext: STPPaymentContext, didFailToLoadWithError error: Error) {
self.delegate?.paymentPopupViewController(controller: self, didFinishPerhapsWithError: error as NSError?)
}
func paymentContextDidChange(_ paymentContext: STPPaymentContext) {
if paymentContext.loading {
self.indicatorView.startAnimating()
} else {
self.indicatorView.stopAnimating()
if paymentContext.selectedPaymentMethod == nil {
self.presentPaymentMehtodsViewController()
}
}
self.indicatorView.isHidden = !paymentContext.loading
self.paymentMethodLabel.isHidden = paymentContext.loading
self.changePaymentMethodButton.isEnabled = !paymentContext.loading
self.payButton.isEnabled = !paymentContext.loading && paymentContext.selectedPaymentMethod != nil
self.paymentMethodLabel.text = paymentContext.selectedPaymentMethod?.label
}
func paymentContext(_ paymentContext: STPPaymentContext, didCreatePaymentResult paymentResult: STPPaymentResult, completion: STPErrorBlock) {
fatalError("Method isn't implemented because our backend makes a charge, not the app.")
}
func paymentContext(_ paymentContext: STPPaymentContext, didFinishWith status: STPPaymentStatus, error: Error?) {
if status == .userCancellation {
return
}
self.delegate?.paymentPopupViewController(controller: self, didFinishPerhapsWithError: error as NSError?)
}
以下是协议规定的委托方法:
@protocol STPPaymentContextDelegate <NSObject>
- (void)paymentContext:(STPPaymentContext *)paymentContext didFailToLoadWithError:(NSError *)error;
- (void)paymentContextDidChange:(STPPaymentContext *)paymentContext;
- (void)paymentContext:(STPPaymentContext *)paymentContext
didCreatePaymentResult:(STPPaymentResult *)paymentResult
completion:(STPErrorBlock)completion;
- (void)paymentContext:(STPPaymentContext *)paymentContext
didFinishWithStatus:(STPPaymentStatus)status
error:(nullable NSError *)error;
如何解决此问题?
答案 0 :(得分:0)
您的实施中存在一些错误。
替换此
func paymentContext(_ paymentContext: STPPaymentContext, didFailToLoadWithError error: Error)
使用
func paymentContext(_ paymentContext: STPPaymentContext, didFailToLoadWithError error: NSError)
并替换此
func paymentContext(_ paymentContext: STPPaymentContext, didFinishWith status: STPPaymentStatus, error: Error?)
使用
func paymentContext(_ paymentContext: STPPaymentContext, didFinishWithStatus status: STPPaymentStatus, error: NSError?)