【问题标题】:Payment via Stripe error show in html Swift通过 Stripe 付款错误显示在 html Swift 中
【发布时间】:2020-01-21 06:04:05
【问题描述】:

我正在我的应用程序中集成条带。该代码有效,但我想得到描述错误并向用户显示警告,以防出现问题(手机号码、邮政编码不正确等)条纹返回以下 html 格式:

Html 格式

<h4>An uncaught Exception was encountered</h4>
<p>Type: Stripe\Exception\InvalidRequestException</p>
<p>Message: You cannot use a live bank account number when making transfers or debits in test mode</p>

问题:如何在应用中显示条带错误?

谁能解释一下如何显示错误。

任何帮助将不胜感激。

提前致谢。

【问题讨论】:

  • 错误的第一部分似乎更像是由需要修复的代码中的错误引起的,但话虽如此,您要显示什么并添加处理此问题的代码错误。
  • 请检查...
  • 您可以在标签或 textView 中将其简单地显示为属性文本,并关闭用户交互

标签: ios swift stripe-payments


【解决方案1】:

一个简单的解决方案是使用 UIwebview/wkwebview 创建自定义警报视图并加载 Html 字符串。如果您不想从 Html 显示所需的消息,则需要解析 Html 字符串并在 AlertViewController 中显示。

此外,您可以将 AlerViewController 与 webview 一起使用。这是一个代码示例,遇到错误时调用此方法:

func showError(with html: String) {
        let alertController = UIAlertController(title: "", message: nil, preferredStyle: .alert)
        let webView = UIWebView()
        webView.loadHTMLString(html, baseURL: nil)
        alertController.view.addSubview(webView)
        webView.translatesAutoresizingMaskIntoConstraints = false
        webView.topAnchor.constraint(equalTo: alertController.view.topAnchor, constant: 45).isActive = true
        webView.rightAnchor.constraint(equalTo: alertController.view.rightAnchor, constant: -10).isActive = true
        webView.leftAnchor.constraint(equalTo: alertController.view.leftAnchor, constant: 10).isActive = true
        webView.heightAnchor.constraint(equalToConstant: 250).isActive = true

        alertController.view.translatesAutoresizingMaskIntoConstraints = false
        alertController.view.heightAnchor.constraint(equalToConstant: 330).isActive = true

        let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
        alertController.addAction(cancelAction)
        self.present(alertController, animated: true, completion: nil)
    }

【讨论】:

    猜你喜欢
    • 2021-12-01
    • 2022-01-16
    • 2017-10-19
    • 2020-04-17
    • 1970-01-01
    • 2021-07-28
    • 2020-08-12
    • 1970-01-01
    • 2014-12-03
    相关资源
    最近更新 更多