doe*_*ost 5 uikit ios qualtrics swift swiftui
我正在尝试使用 qualtrics 制作一个简单的 swiftui 应用程序,并且我正在尝试使用 uiviewrepresentable 来使其工作
@main
struct QualtricsPocApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
init() {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
// i have the actual intercept id's here i just removed them
Qualtrics.shared.initializeProject(brandId: "brand", projectId: "proj", extRefId: "ref", completion: { (myInitializationResult) in print(myInitializationResult);})
return true
}
}
}
struct QualtricsViewRep: UIViewControllerRepresentable {
typealias UIViewControllerType = UIViewController
func makeUIViewController(context: Context) -> UIViewController {
let vc = UIViewController()
Qualtrics.shared.evaluateProject { (targetingResults) in
for (interceptID, result) in targetingResults {
if result.passed() {
let displayed = Qualtrics.shared.display(viewController: self, autoCloseSurvey: true)
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
在 let displayed = ... 我不断收到错误“无法将类型 'QualtricsViewRep' 的值转换为预期参数类型 'UIViewController'”,如何将此代码作为 UIViewController 返回以在 swiftui 应用程序中使用,或者是否有一些我应该以其他方式解决这个问题?
不幸的是,我没有安装 Qualtrics,但我已经在 UIKit 中使用了它。我的假设是您需要创建 UIViewController 的实例。该视图控制器是 qualtrics 视图将呈现的内容。
最终,您将返回视图控制器,其中包含在其上呈现的质量视图。
struct QualtricsViewRep: UIViewControllerRepresentable {
typealias UIViewControllerType = UIViewController
func makeUIViewController(context: Context) -> UIViewController {
let vc = UIViewController()
Qualtrics.shared.evaluateProject { (targetingResults) in
for (interceptID, result) in targetingResults {
if result.passed() {
DispatchQueue.main.async {
let vc = UIViewController()
let displayed = Qualtrics.shared.display(viewController: vc, autoCloseSurvey: true)
}
}
}
}
return vc
}
func updateUIViewController(_ uiViewController: UIViewController, context: Context) {
// your code here
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
374 次 |
| 最近记录: |