【发布时间】:2021-10-28 15:43:39
【问题描述】:
对不起,如果标题令人困惑,我对整个事情有点陌生。
我正在尝试将 PassBase ID 验证集成到我的应用程序中,该应用程序是使用 SwiftUI 构建的,他们的文档提供了使用 Swift 和视图控制器的说明。 我的问题是,有没有办法将 Swift 代码部分插入到我的 SwiftUI 视图中?
他们文档中的代码示例:
import Passbase
import UIKit
class ViewController: UIViewController, PassbaseDelegate {
override func viewDidLoad() {
super.viewDidLoad()
PassbaseSDK.delegate = self
// Optional - You can prefill the email to skip that step.
Passbase.prefillUserEmail = "testuser@yourproject.com"
let button = PassbaseButton(frame: CGRect(x: 40, y: 90, width: 300, height: 60))
self.view.addSubview(button)
}
func onFinish(identityAccessKey: String) {
print("onFinish with identityAccessKey \(identityAccessKey)")
}
func onSubmitted(identityAccessKey: String) {
print("onSubmitted with identityAccessKey \(identityAccessKey)")
}
func onError(errorCode: String) {
print("onError with code \(errorCode)")
}
func onStart() {
print("onStart")
}
}
据我了解,这部分代码应该在 VC 中创建一个按钮。 我的目标是将此按钮与功能添加到我的 SwiftUI 视图中。
完整文档:https://docs.passbase.com/ios#general
提前感谢大家的帮助!
【问题讨论】:
-
您的意思是 将 UIKit 插入 SwiftUI。 Here is an Apple tutorial 怎么做。