Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/96.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 使用SwiftUI的Braintree插件_Ios_Swift_Uikit_Swiftui_Braintree - Fatal编程技术网

Ios 使用SwiftUI的Braintree插件

Ios 使用SwiftUI的Braintree插件,ios,swift,uikit,swiftui,braintree,Ios,Swift,Uikit,Swiftui,Braintree,我正在尝试使用Braintree设置付款,但是Braintree还不支持SwiftUI,所以我必须将其与UIKit集成。我使用UIViewControllerRepresentable创建了一个包装器,并使用sheet函数将其呈现为一个模态;然而,它并没有像预期的那样工作,它似乎打开了两个模态 打开模式时的屏幕: Button(action: { self.checkout = true }) { HStack { Spacer() Text("C

我正在尝试使用Braintree设置付款,但是Braintree还不支持SwiftUI,所以我必须将其与UIKit集成。我使用UIViewControllerRepresentable创建了一个包装器,并使用sheet函数将其呈现为一个模态;然而,它并没有像预期的那样工作,它似乎打开了两个模态

打开模式时的屏幕:

Button(action: {
    self.checkout = true
}) {
    HStack {
        Spacer()
        Text("Checkout")
            .fontWeight(.bold)
            .font(.body)
        Spacer()
    }
    .padding(.vertical, 12)
    .foregroundColor(.white)
    .background(Color.blue)
}.sheet(isPresented: self.$checkout) {
    BTDropInRepresentable(authorization: self.token!, handler:  { (controller, result, error) in
                       if (error != nil) {
                           print("ERROR")
                       } else if (result?.isCancelled == true) {
                           print("CANCELLED")
                       } else if result != nil {
                        print("SUCCESS")
                           // Use the BTDropInResult properties to update your UI
                           // result.paymentOptionType
                           // result.paymentMethod
                           // result.paymentIcon
                           // result.paymentDescription
            }
        controller.dismiss(animated: true, completion: nil)
    })
}
这是我的包装纸:

import SwiftUI
import BraintreeDropIn

struct BTDropInRepresentable: UIViewControllerRepresentable {
    var authorization: String
    var handler: BTDropInControllerHandler

    init(authorization: String, handler: @escaping BTDropInControllerHandler) {
        self.authorization = authorization
        self.handler = handler
    }

    func makeUIViewController(context: Context) -> BTDropInController {
        let bTDropInController = BTDropInController(authorization: authorization, request: BTDropInRequest(), handler: handler)!
        return bTDropInController
    }

    func updateUIViewController(_ uiViewController: BTDropInController, context: UIViewControllerRepresentableContext<BTDropInRepresentable>) {
    }
}
有没有人有在SwiftUI中使用Braintree或类似情况的经验?我是做错了什么还是忘记了什么? 我知道为Braintree签出编写自己的视图是一种选择,但我希望避免这种情况


谢谢

看看您收到的错误,我打赌它与您需要添加的自定义URL方案有关:

注册URL类型


您还需要设置您的直接付款方式,这些都在我链接的指南中有详细说明。

谢谢!但我使用信用卡支付,因此如果这真的相关,则没有。@MorizMartiner好的,但我非常确定,即使信用卡显示在弹出窗口中,您仍然需要实现BTDropInResult结果值。