【问题标题】:Stripe Fabric iOS integrationStripe Fabric iOS 集成
【发布时间】:2016-11-15 03:28:58
【问题描述】:

我正在尝试使用 Fabric 设置 Stripe,我的第一步当然是接受用户的信用卡信息。使用下面的代码,提交按钮会在应该启用时启用,但单击按钮时应用程序会崩溃。错误消息是“由于未捕获的异常 'NSInvalidArgumentException' 导致应用程序终止,原因:'-[Stripe3.ViewController submitCard:]: unrecognized selector sent to instance 0x7fe83740dbd0'”

如果有任何见解,我将不胜感激!

class ViewController: UIViewController, STPPaymentCardTextFieldDelegate{

var paymentTextField: STPPaymentCardTextField! = nil
var submitButton: UIButton! = nil


override func viewDidLoad() {
    super.viewDidLoad()
    paymentTextField = STPPaymentCardTextField(frame: CGRectMake(15, 30, view.frame.width - 30, 44))
    paymentTextField.delegate = self
    view.addSubview(paymentTextField)
    submitButton = UIButton(type: UIButtonType.system)
    submitButton.frame = CGRectMake(15, 100, 100, 44)
    submitButton.isEnabled = false
    submitButton.setTitle("Submit", for: UIControlState.normal)

    submitButton.addTarget(self, action: Selector(("submitCard:")), for: UIControlEvents.touchUpInside)

    view.addSubview(submitButton)

    // Do any additional setup after loading the view, typically from a nib.
}

func paymentCardTextFieldDidChange(_ textField: STPPaymentCardTextField) {
    submitButton.isEnabled = textField.valid
}

@IBAction func submitCard(sender: AnyObject?) {
    // If you have your own form for getting credit card information, you can construct
    // your own STPCardParams from number, month, year, and CVV.
    let card = paymentTextField.card!

    STPAPIClient.shared().createToken(withCard: card) { token, error in
        guard let stripeToken = token else {
            NSLog("Error creating token: %@", error!.localizedDescription);
            return
        }

        // TODO: send the token to your server so it can create a charge
        let alert = UIAlertController(title: "Welcome to Stripe", message: "Token created: \(stripeToken)", preferredStyle: .alert)
        alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
        self.present(alert, animated: true, completion: nil)
    }
}

【问题讨论】:

    标签: ios swift stripe-payments twitter-fabric


    【解决方案1】:

    确保您已将按钮故事板的操作正确链接到正确的 UIViewController 子类中的正确 IBAction。有时这只是 Storyboard 的场景/UI 组件复制/粘贴错误的问题。

    【讨论】:

      猜你喜欢
      • 2014-07-23
      • 2015-01-05
      • 2017-02-16
      • 2018-12-27
      • 1970-01-01
      • 1970-01-01
      • 2021-05-03
      • 2017-04-04
      • 2018-07-24
      相关资源
      最近更新 更多