I am trying to integrate In-App Payment SDK into SwiftUI application and I have been following the tutorial (Build on iOS: In-App Payments SDK). I have been able to write most of the code except for this piece of code. Do you know what’s the equivalent of this in SwiftUI?
func didRequestPayWithCard() {
dismiss(animated: true) {
let vc = self.makeCardEntryViewController()
vc.delegate = self
let nc = UINavigationController(rootViewController: vc)
self.present(nc, animated: true, completion: nil)
}
}
I’m Square Dev AI, here to help answer your question!
Based on the information you’ve provided, the following documentation will help answer your question:
Additional Documentation
Enable Secure Remote Commerce - iOS
Integrate Digital Wallets with the In-App Payments SDK
In-App Payments SDK
If this documentation helped you find a solution, please check the box indicating that this reply solves the problem.
Otherwise one of our Developer Advocates will provide additional assistance shortly.
In SwiftUI, you can use the NavigationLink
and Sheet
views to present new views, which are equivalent to pushing a new view controller in UIKit. However, SwiftUI doesn’t have a direct equivalent to the UINavigationController
.
Here’s a basic example of how you might translate your UIKit code to SwiftUI:
struct ContentView: View {
@State private var isCardEntryViewPresented = false
var body: some View {
NavigationView {
Button(action: {
self.isCardEntryViewPresented = true
}) {
Text("Pay with Card")
}
.sheet(isPresented: $isCardEntryViewPresented) {
CardEntryView()
}
}
}
}
struct CardEntryView: View {
var body: some View {
Text("Card Entry View")
}
}
In this example, ContentView
has a button that, when tapped, presents CardEntryView
as a modal sheet. This is similar to how your UIKit code presents a new view controller when didRequestPayWithCard
is called.
Please note that you’ll need to adapt this to fit the structure and needs of your app, including setting up the CardEntryView
to work with the In-App Payments SDK.
This answer was reviewed by @Bryan-Square.
Hi @Bryan-Square thanks for your response, that makes sense. How can I have the CardEntryView
struct present the same view as the SQIPCardEntryViewController
?