I’m trying to make a simple swiftui app using qualtrics and I’m trying to use a uiviewrepresentable to make it work
@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)
}
}
}
}
on let displayed = … I keep getting the error "Cannot convert value of type ‘QualtricsViewRep’ to expected argument type ‘UIViewController’", how can I return this code as a UIViewController to use in a swiftui app, or is there some other way I should be approaching this?
2
Answers
Unfortunately I don’t have Qualtrics installed, but I have worked with it within UIKit. My assumption here is that you will need to create an instance of a UIViewController. This view controller is what the qualtrics view will present itself over.
Ultimately, you will return the view controller which contains the qualtrics view presented over it.
Sample Qualtrics SwiftUI App
I had to implement this for work so I decided to share my solution.
QualtricsDemoApp
ContentView
Now I just have to figure out why it’s not in English. 😃