【发布时间】: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