Core
Currently, we have new version of the SDK available. (Click to see more information)
4.3.2 🚀 Latest
The Core library allows you to start the flow of the user and allows you to communicate between the modules and the server.
Quick start
Add AKCoreSwift
as a dependency
in your Package Dependencies
app.
https://github.com/Autentikar/core-spm.git
Set up
Initialize SDK
Before continuing, you can set up the SDK with the following code, we recommend that you do this in the AppDelegate
class:
import AKCoreSwift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
.....
AKCore.basicAuth(user: "your_user_key", password: "your_password_key")
AKCore.start(as: "your_signature_key")
.....
return true
}
Basic configuration
To configure the flow start into your specific ViewController you have to call the start
method of the AKCore
class with multiple init flow options.
AKCoreOptions.account
parameter is mandatory.The following example shows how to start the flow with different options:
inFlowID
import AKCoreSwift
@objc func startFlow(sender: UIButton!) {
AKCoreOptions.account = "your_account"
let options = AKCoreOptions.start.inFlowID(flowId: "your_flow_id",
user: User(country: "CL", docType: "CI", idNum: "0000"),
stage: .dev | .qa | .prod, responseType: .instance_response)
AKCore.start(self, options: options)
}
inExternalApp
import AKCoreSwift
@objc func startFlow(sender: UIButton!) {
AKCoreOptions.account = "your_account"
let options = AKCoreOptions.start.inExternalApp(nextToken: "your_next_token", authToken: "your_auth_token", stage: .dev | .qa | .prod)
AKCore.start(self, options: options)
}
Options
The AKCoreOptions
class is a class that allows you to configure the flow init, it has the following basic option:
account
The account
property is a property that allows you to configure the account that you want vinculate to the flow. Is mandatory for new accounts created after 2023-04-01.
timeout
The timeout
property allows you to configure the timeout of the petitions, for default is 60 seconds.
start
The start
property is a class that allows you to configure the flow start, it has the following options:
inFlowID
The inFlowID
method is a method that allows you to configure the flow start with the following parameters:
- flowID: The flow id that you want to start.
- user: The
user
class that will start the flow. - stage: The stage of the flow that you want to start, for default is PROD.
- customFields: The custom fields that you want to send to the flow.
- files: The files that you want to send to the flow, it's
[String:String]
type, you can add files in base64. - responseType: The type of response that the SDK will return to the application, for default is
.result
.
inExternalApp
The inExternalApp
method is a method that allows you to resume a previous flow the next step with the following parameters:
- nextToken: The next token is an identifier that allows you to start a flow from an external application.
- authToken: The auth token is an identifier that allows you validate the app that is starting the flow.
- stage: The stage of the flow that you want to start, for default is PROD.
User
The User
class is a class that allows you to configure the user that will start the flow, it has the following options:
- country: The country of the user.
- docType: The document type of the user.
- idNum: The document number of the user.
ResponseType
The ResponseType
class is an enum that allows you to configure the type of response that the SDK will return to the application, it has the following options:
- RESULT: Returns the result of the last step.
- INSTANCE_ID: Returns the instance id of the current flow.
- INSTANCE_RESPONSE: Returns the final result of the flow.
- FULL: Return all the information of the flow.
AKCoreDelegate
The AKCoreDelegate
is a delegate that allows you to return the result of the flow to the application, it has the following options:
inFlowID & inExternalApp
import AKCoreSwift
extension InitViewController : AKCoreDelegate {
func onSuccess(_ result: Any?) {
if let result = result as? AKReturn,
let map = result.instanceResponse as? [String: AnyCodable] {
do {
let jsonData = try JSONEncoder().encode(map)
let jsonString = String(data: jsonData, encoding: .utf8)!
print(jsonString)
} catch {
print("Error: \(error.localizedDescription)")
}
}
}
func onFailure() {
// App or User canceled the flow
}
}
In this example we are using the AKReturn
class to return the result of the flow.
AKReturn
The AKReturn
class is a class that allows you to return the result of the flow to the application, it has the following options:
- result: The result of the last step, it's of type Any but it is Dynamic Json.
- instanceId: The instance id of the current flow.
- instanceResponse: The final result of the flow, it's of type Any but it is
[String: AnyCodable]
type.
Custom Theme
If you want to use a custom theme you have to add the AKCoreCustomization
class:
- LoadingScreen: change theme of the loading screen is shared between steps.
import AKCoreSwift
let customPrincipal = AKCoreCustomization()
let loadingScreen = AKCoreCustomization.LoadingScreen()
let coreButtonCustom = AKCoreCustomization.Button()
customPrincipal.backgroundColor = UIColor.your_background_color
customPrincipal.showBackgroundImage = true | false
customPrincipal.backgroundImage = UIImage(named: "your_background_image")
customPrincipal.showLogo = true | false
customPrincipal.logo = UIImage(named: "your_logo")
customPrincipal.activityViewColor = UIColor.your_activity_view_color
customPrincipal.textColor = UIColor.your_text_color
customPrincipal.customFont = UIFont(name: "your_custom_font", size: 18)
customPrincipal.bundleForLocalizableString = Bundle(identifier: "your_identifier")!
// Loading Screen
loadingScreen.backgroundColor = UIColor.your_background_color
loadingScreen.showBackgroundImage = true | false
loadingScreen.backgroundImage = UIImage(named: "your_background_image")
loadingScreen.showLogo = true | false
loadingScreen.logo = UIImage(named: "your_logo")
loadingScreen.activityViewColor = UIColor.your_activity_view_color
loadingScreen.textColor = UIColor.your_text_color
loadingScreen.customFont = UIFont(name: "your_custom_font", size: 18)
// Button
coreButtonCustom.backgroundColor = UIColor.your_background_color
coreButtonCustom.textColor = UIColor.your_text_color
coreButtonCustom.disableTextColor = UIColor.your_disable_text_color
coreButtonCustom.disableBackgroundColor = UIColor.your_disable_background_color
coreButtonCustom.customFont = UIFont(name: "your_custom_font", size: UIFont.labelFontSize)
customPrincipal.loadingScreenCustomization = loadingScreen
customPrincipal.buttonCustomization = coreButtonCustom
AKCore.setCustomization(customization: customPrincipal)
Properties
This class has the following properties:
Principal screen
- backgroundColor: The background color of principal screen.
- showBackgroundImage: Show or hide the background image in principal screen (default is false).
- backgroundImage: The background image of principal screen (if showBackgroundImage is false this image not show).
- showLogo: Show or hide the logo in principal screen (default is true).
- logo: The logo bottom of principal screen (if showLogo is false this image not show).
- activityViewColor: The color of progress bar in principal screen.
- textColor: The color of text in principal screen.
- bundleForLocalizableString: The bundle for localizable string.
- customFont: The custom font of text in principal screen. Deprecated
- titleFont: The custom font of title in principal screen. New
- textFont: The custom font of text in principal screen. New
- fileViewerCustomization: The custom style of file viewer. New
- otpCustomization: The custom style of otp. New
Loading screen
- backgroundColor: The background color.
- showBackgroundImage: Show or hide the background image (default is false).
- backgroundImage: The background image (if showBackgroundImage is false this image not show).
- showLogo: Show or hide the logo (default is true).
- logo: The logo bottom (if showLogo is false this image not show).
- activityViewColor: The color of progress bar.
- textColor: The color of text.
- customFont: The custom font typeface.
Button
- backgroundColor: The background color. Deprecated
- primaryBackgroundColor: The primary background color. New
- secondaryBackgroundColor: The secondary background color. New
- textColor: The color of text. Deprecated
- primaryTextColor: The primary color of text. New
- secondaryTextColor: The secondary color of text. New
- disableTextColor: The color of text when the button is disabled.
- disableBackgroundColor: The background color when the button is disabled.
- customFont: The custom font typeface button. Deprecated
- font: The font typeface button. New
- textSize: The size of text.
FileViewer
This properties are available from version 4.3.0.
- backgroundColor: The background color of the file viewer.
- textColor: The color of the text in the file viewer.
- checkBoxColorWhenChecked: The color of the checkbox when is checked.
- checkBoxColorWhenNotchecked: The color of the checkbox when is unchecked.
- image: The image of the file viewer.
- tableBorderColor: The border color of the table.
OTP
This properties are available from version 4.3.0.
- borderColor: The border color of the otp text.
- borderTextColor: The text color of the otp text.
Texts (Localizable)
For change the texts you have to add or modify the Localizable.strings
file in your project, the keys are the following:
// Core SDK
"UIStartingAuth" = "Starting Auth Client & SDK";
"UIEndAuth" = "Ending Authentication";
"UIProcessingData" = "Processing ";
"UIEndVerification" = "Ending Verification";
"UICancelOperation" = "Canceling Operation";
"UINextFLow" = "Next Flow";
"UIResult" = "Result";
"UIConfiguration" = "Configuration";
"UIValidate" = "Validate";
"UIValidateAgain" = "Validate again";
"UICancel" = "Cancel";
"UIPermissionRequiredLocationServiceTitle" = "Permissions required";
"UIPermissionRequiredLocationServiceDescription" = "Please enable location permissions in settings.";
"UIInformation" = "Information";
"AcceptDocuments" = "To continue you must accept\nthe documents. (%d)";
"LoadingDocuments" = "Loading documents";
"HavingTroubleDocument" = "Having trouble viewing the document? Please close the viewer and reopen it.";
"OtpTitle" = "SMS Capture";
"OtpMessage" = "To ensure the security of your transaction, we have sent a verification code to your registered mobile number.";
"OtpSendCode" = "Verify OTP code";
"OtpResendCode" = "Resend OTP code";
"OtpVerifierCode" = "Verifying OTP code";
"OtpResendCode" = "Resending OTP code";
"OtpFooterMessage" = "If you have not received the OTP code, you can request a new code that will be sent to your cell phone.";
"OtpSentSuccessfully" = "OTP code sent";
"OtpSentNotSuccessfully" = "The OTP code was not sent, try again";
"OtpNotValidOrExpired" = "The OTP code is invalid or has expired.\nPlease try again.";
"OtpNotValid" = "The OTP code is invalid.";
// Network Events
"NetworkEventNoInternetConnection" = "Make sure your device is connected to the network.";
"NetworkEventServerError" = "An error has occurred on the server.\nContact the administrator for more information.";
"NetworkEventGeneralError" = "An internal error has occurred.\nContact the administrator for more information.";
"NetworkEventFailedMappingData" = "An error occurred while reading the data as it is not in the correct format.";
"NetworkEventFailedMappingStart" = "An error occurred while starting the flow.";
"NetworkEventFailedSignatureSDK" = "Failed to retrieve SDK signature.";
"NetworkEventInvalidSignatureSDK" = "The SDK signature is invalid or has expired.";
"NetworkEventInvalidBundleIdentifier" = "Bundle Identifier is invalid with SDK signature.";
"NetworkEventFailedEncryptData" = "An error occurred while encrypting the data.";
"NetworkEventTimeoutError" = "The waiting time has been exceeded.\nPlease try again.";
// Dynamic Flow Events
"DynamicFlowEventWithoutData" = "Without in the previous model.";
"DynamicFlowEventWithoutHeaderData" = "Without in the header.";
"DynamicFlowEventNoAction" = "The process to be followed has not been identified.";
"DynamicFlowEventNoControllerRegister" = "The controller has not been previously registered.";
"DynamicFlowEventModelNoMatch" = "The model does not match the required.";
"DynamicFlowEventAuthExpired" = "This authentication has expired.\nDo the process again.";
"DynamicFlowEventAuthNoAvaible" = "This authentication is not available.";
"DynamicFlowEventMaxRetries" = "The maximum number of retries has been exceeded.\nTry again later.";
// Alert Text
"AlertErrorConnectionTitle" = "Connection error";
"AlertErrorCommunicationTitle" = "Communication error";
"AlertErrorExecutionTitle" = "Execution error";
"AlertErrorValidationTitle" = "Validation error";
"AlertOk" = "OK";
"AlertRetry" = "Retry";