iOS
The userRedirectUrl field is used to redirect the user. This field is received in the successful process creation response when making the Process Creation request. Here you will find the best way to manage the user experience, using ASWebAuthenticationSession, in your iOS application:
Step 1: Create the authentication controller
1 - The first step is to create the authentication controller, so create a class called UnicoAuthenticationController (or any name you prefer).
2 - Next, import the AuthenticationServices framework at the top of the class.
3 - Declare the class as NSObject and implement the ASWebAuthenticationPresentationContextProviding protocol.
The result should be:
import AuthenticationServices
class UnicoAuthenticationController: NSObject, ASWebAuthenticationPresentationContextProviding {
func presentationAnchor(for session: ASWebAuthenticationSession) -> ASPresentationAnchor {
if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene {
if let mainWindow = windowScene.windows.first {
return mainWindow
}
}
return ASPresentationAnchor()
}
}Step 2: Implement authentication
1 - Open the file where you perform the authentication and add the necessary imports (for example, ContentView.swift is used).
import SwiftUI
import AuthenticationServices2 - To control the flow state, create the @State property.
@State private var finished = false3 - Create an instance of the UnicoAuthenticationController class outside the body of the ContentView struct.
let unicoController = UnicoAuthenticationController()4 - For process validation, create a function called redirectUser.
func redirectUser() {
guard let url = URL(string: "URL_AUTHENTICATION") else { return }
var session: ASWebAuthenticationSession?
session = ASWebAuthenticationSession(url: url, callbackURLScheme: "BUNDLE") { callbackURL, error in
guard callbackURL != nil else {
if let error = error {
return print("Erro durante o processo: \(error.localizedDescription)")
}
return
}
// Process the callback URL to check whether the process was completed.
session?.cancel()
finished = true
}
session?.presentationContextProvider = unicoController
session?.prefersEphemeralWebBrowserSession = true
session?.start()
}It is also possible to use the link generated by Unico in hybrid frameworks. To do this, you can create a bridge between the framework used and the native one and follow as we suggest in the documents or use a library that makes these integration options available.
Integrating WebView into your application is the customer's sole responsibility, as this functionality is not offered as part of Unico's libraries or SDKs. Because of this, we do not offer technical support for questions or problems related to implementing WebView in your application. For configuration guidance, we recommend consulting the official documentation for the technology used in your project (e.g. React Native, Flutter, etc.).
Last updated
Was this helpful?