Ios 在html Swift中通过条带错误显示付款

Ios 在html Swift中通过条带错误显示付款,ios,swift,stripe-payments,Ios,Swift,Stripe Payments,我正在我的应用程序中集成stripe。代码正常工作,但我希望获得描述错误,并在出现错误(手机号码、邮政编码不正确等)时向用户显示该错误并发出警报。条带返回html格式如下: Html格式 <h4>An uncaught Exception was encountered</h4> <p>Type: Stripe\Exception\InvalidRequestException</p> <p>Message: You cannot us

我正在我的应用程序中集成stripe。代码正常工作,但我希望获得描述错误,并在出现错误(手机号码、邮政编码不正确等)时向用户显示该错误并发出警报。条带返回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>
遇到未捕获的异常
类型:条带\Exception\InvalidRequestException

消息:在测试模式下进行转账或借记时,您不能使用实时银行帐号

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

有人能给我解释一下如何显示错误吗

任何帮助都将不胜感激


提前感谢。

一个简单的解决方案是使用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)
    }

错误的第一部分似乎更像是由需要修复的代码中的错误引起的,但话说回来,您希望显示什么并添加处理此错误的代码。请检查…您可以在标签或文本视图中简单地将其显示为属性文本,而不需要用户干预