【发布时间】:2021-03-14 01:49:47
【问题描述】:
我正在努力将 Stripe 添加到我的项目中。还有比这更多的代码,但在我开始添加 Stripe 和 init 之前,这一切都在工作。这是 Stripe 说要在 their docs 中使用的 init
这是我的开始代码和初始化代码:
class BusinessOwnerVC: UIViewController, MyProtocol {
let paymentContext: STPPaymentContext
init() {
let customerContext = STPCustomerContext(keyProvider: SwiftAPI())
self.paymentContext = STPPaymentContext(customerContext: customerContext)
super.init(nibName: nil, bundle: nil)
self.paymentContext.delegate = self
self.paymentContext.hostViewController = self
self.paymentContext.paymentAmount = 5000 // This is in cents, i.e. $50 USD
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
.....
我正在使用 Storyboard,因为我听说这很重要。当我运行代码时,会抛出 fatalError 并使应用程序崩溃。 The Stripe example project 里面有这个确切的代码,它可以工作。
为什么我的应用程序崩溃了?这所需的 init 甚至在做什么?我想我明白我为什么需要它,但如果您能在子类所需之外进行详细说明,那将很有帮助。
【问题讨论】:
-
在使用 Storyboards 时需要它(Stripe 示例应用程序不需要,因此构造函数实际上不会被调用),因为 UIStoryboard 将使用该构造函数来实例化您的 BusinessOwnerVC。
标签: ios swift sdk stripe-payments