Stripe Fabric iOS 集成
Posted
技术标签:
【中文标题】Stripe Fabric iOS 集成【英文标题】:Stripe Fabric iOS integration 【发布时间】: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)
【问题讨论】:
【参考方案1】:确保您已将按钮故事板的操作正确链接到正确的 UIViewController 子类中的正确 IBAction。有时这只是 Storyboard 的场景/UI 组件复制/粘贴错误的问题。
【讨论】:
以上是关于Stripe Fabric iOS 集成的主要内容,如果未能解决你的问题,请参考以下文章
HyperLedger Fabric安装在中间并且在MacOS中没有进展?
是否可以将 Stripe 与 Firebase 和 iOS 集成?