- Open your project in Xcode.
- Select
File
>Add Package Dependency...
. - Enter the URL of the Quiltt Connector Swift SDK repository, select the latest version and click
Add Package
. - The Quiltt Connector Swift SDK is now integrated into your project. You can import it in your Swift files with
import QuilttConnector
.
After importing QuilttConnector
, you can use its classes and methods in your code. Here's a basic example:
import SwiftUI
import QuilttConnector
import WebKit
struct ConnectorView: View {
@Binding var showHomeView: Bool
@Binding var connectionId: String
var body: some View {
WebView(showHomeView: $showHomeView, connectionId: $connectionId)
}
}
struct WebView: UIViewRepresentable {
@Binding var showHomeView: Bool
@Binding var connectionId: String
@State var config = QuilttConnectorConnectConfiguration(
connectorId: "<CONNECTOR_ID>",
oauthRedirectUrl: "<YOUR_HTTPS_UNIVERSAL_LINK>"
)
func makeUIView(context: Context) -> WKWebView {
let quilttConnector = QuilttConnector.init()
quilttConnector.authenticate(token: "<SESSION_TOKEN>")
let webview = quilttConnector.connect(config: config,
onEvent: { eventType, metadata in
print("onEvent \(eventType), \(metadata)")
},
onExitSuccess: { metadata in
print("onExitSuccess \(metadata)")
connectionId = metadata.connectionId!
showHomeView = true
},
onExitAbort: { metadata in
print("onExitAbort \(metadata)")
showHomeView = true
},
onExitError: { metadata in
print("onExitError \(metadata)")
showHomeView = true
})
return webview
}
func updateUIView(_ uiView: WKWebView, context: Context) {
// Use this method to update the WKWebView with new configuration settings.
}
}
#Preview {
ConnectorView(showHomeView: .constant(false), connectionId: .constant("connectionId"))
}