gpt4 book ai didi

ios - 非 -'@objc' 方法 'paymentAuthorizationViewControllerDidFinish' 不满足 '@objc' 协议(protocol)的要求

转载 作者:行者123 更新时间:2023-11-29 05:46:03 29 4
gpt4 key购买 nike

编译出错

Non-'@objc' method 'paymentAuthorizationViewControllerDidFinish' does not satisfy requirement of '@objc' protocol 'PKPaymentAuthorizationViewControllerDelegate'

如果我在 paymentAuthorizationViewControllerDidFinish 之前添加 @objc,则会收到新错误

@objc can only be used with members of classes, @objc protocols, and concrete extensions of classes.

我可以直接使用 PKPaymentAuthorizationViewControllerDelegate 扩展 Handler,但我有两个扩展 ApplePayable 的不同类,并且我不想为不同的类编写相同的扩展

import UIKit
import PassKit

class ApplePayRequestComposer {}

protocol ApplePayable: PKPaymentAuthorizationViewControllerDelegate {

func applePaymentSheet(composer: ApplePayRequestComposer) -> PKPaymentAuthorizationViewController?
func processPKPayment(payment:PKPayment, completed:@escaping (_ success:Bool)->())
}


extension ApplePayable {

func applePaymentSheet(composer: ApplePayRequestComposer) -> PKPaymentAuthorizationViewController?{
return nil
}

func processPKPayment(payment:PKPayment, completed:@escaping (_ success:Bool)->()) {
completed(false)
}
}

// PKPaymentAuthorizationViewControllerDelegate implementation
extension ApplePayable
{
func paymentAuthorizationViewControllerDidFinish(_ controller: PKPaymentAuthorizationViewController) {
controller.dismiss(animated: true, completion: nil)
}

@available(iOS 11.0, *)
func paymentAuthorizationViewController(_ controller: PKPaymentAuthorizationViewController, didAuthorizePayment payment: PKPayment, handler completion: @escaping (PKPaymentAuthorizationResult) -> Swift.Void) {
processPKPayment(payment: payment) { success in
let status = success ? PKPaymentAuthorizationStatus.success:PKPaymentAuthorizationStatus.failure
let result = PKPaymentAuthorizationResult(status: status, errors: nil)
completion(result)
}
}

func paymentAuthorizationViewController(_ controller: PKPaymentAuthorizationViewController, didAuthorizePayment payment: PKPayment, completion: @escaping (PKPaymentAuthorizationStatus) -> Swift.Void) {
processPKPayment(payment: payment) { success in
completion(success ? PKPaymentAuthorizationStatus.success: PKPaymentAuthorizationStatus.failure)
}
}
}

class Handler: NSObject, ApplePayable
{

}

最佳答案

尝试将@objc放在func paymentAuthorizationViewControllerDidFinish之前。

    @objc func paymentAuthorizationViewControllerDidFinish(_ controller: PKPaymentAuthorizationViewController) {
controller.dismiss(animated: true, completion: nil)
}

关于ios - 非 -'@objc' 方法 'paymentAuthorizationViewControllerDidFinish' 不满足 '@objc' 协议(protocol)的要求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56144059/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com