【发布时间】:2022-09-23 07:46:57
【问题描述】:
我正在尝试将 Person SDK v2 集成到 SwiftUI 视图中。 UIKit 设置为从特定的 UIViewController 呈现。这是我的代码。 https://docs.withpersona.com/docs/ios-sdk-v2-integration-guide
我不确定如何从 SwiftUI 调用我的 present 函数。 SDK 已设置,因此当您创建该 Inquiry 对象时,它会触发它的导航以显示在视图控制器上。
struct PersonaInquiry: UIViewControllerRepresentable {
private var viewController = UIViewController()
private var coordinator = Coordinator()
class Coordinator: NSObject, InquiryDelegate {
func inquiryComplete(inquiryId: String, status: String, fields: [String : Persona2.InquiryField]) {
}
func inquiryCanceled(inquiryId: String?, sessionToken: String?) {
}
func inquiryError(_ error: Error) {
}
}
func makeUIViewController(context: Context) -> UIViewController {
return viewController
}
func updateUIViewController(_ uiViewController: UIViewController, context: Context) {
}
func present(templateId: String) {
let config = InquiryConfiguration(templateId: templateId)
// Create the inquiry with the view controller
// as the delegate and presenter.
Inquiry(config: config, delegate: coordinator).start(from: viewController)
}
func makeCoordinator() -> Coordinator {
return coordinator
}
}
struct PersonaInquiry_Previews: PreviewProvider {
static var previews: some View {
PersonaInquiry()
}
}
-
看看this setup,这是一种不同的方法。
标签: ios swift swiftui uiviewcontrollerrepresentable