AccountManager

@objc
public class AccountManager : NSObject

A singleton class for performing all the workflows related to user registration, signing in, signing out and other.

  • Current sign-in status.

    Declaration

    Swift

    @objc
    public static var isAuthenticated: Bool { get }
  • The currently signed-in user.

    Declaration

    Swift

    @objc
    public static var currentUser: User? { get }
  • Current Biometric login enabled status.

    Declaration

    Swift

    @objc
    public internal(set) static var isBiometricsSignInEnabled: Bool { get set }
  • The access token for the current user used to autherize API requests to the server.

    Declaration

    Swift

    @objc
    public static var accessToken: String? { get set }
  • A boolean value indicating whether user has selected to be kept signed in in the previous log in.

    Declaration

    Swift

    @objc
    public static var keepUserSignedIn: Bool { get }
  • Indicating whether SDK has persisted session data, either with Biometric protection or not.

    Declaration

    Swift

    @objc
    public static var hasUser: Bool { get }
  • A boolean value indicating whether the user logged in with temporary password.

    Declaration

    Swift

    @objc
    public static var isLoggedInWithTemporaryPassword: Bool { get }
  • Register a new user.

    Note

    This method will validate the password according to the server’s password policy and might fail with a list of validation errors. You can also do the password validation using the PasswordManager class before calling this method.

    Declaration

    Swift

    @objc
    public static func register(user: User,
                                password: String,
                                session: String = "",
                                policyValidation: Bool = true,
                                completion: @escaping ([NSError]) -> Void)
    Parameters
    user

    A User object with complete list of details. All none optional fields should be provided.

    password

    New password.

    session

    The session ID for the OTP.

    policyValidation

    Whether to validate the password policy before sending the request to server.

    completion

    Completion block to be called after either registration is complete or errors occured.

  • Sign user in with a password.

    Declaration

    Swift

    @objc
    public static func signIn(userId: String,
                              password: String,
                              keepMeSignIn: Bool = false,
                              completion: @escaping (NSError?) -> Void)
    Parameters
    userId

    User ID. Either email address or mobile phone number

    password

    Password

    keepMeSignIn

    Indicating whether SDK should keep session alive after app relaunched

    completion

    Completion block to be called after either sign in is complete or errors occurred.

  • A convinience method for registering user and automatically sign in if registration is successful. This method is the same as calling register(user:password:completion) and signIn(userId:password:keepMeSignIn:completion) methods separately.

    Declaration

    Swift

    @objc
    public static func registerAndSignIn(user: User,
                                         password: String,
                                         keepMeSignIn: Bool = false,
                                         session: String = "",
                                         policyValidation: Bool = true,
                                         completion: @escaping ([NSError]) -> Void)
    Parameters
    user

    A User object with complete list of details. All none optional fields should be provided.

    password

    New password

    keepMeSignIn

    Indicating whether SDK should keep session alive after app relaunched.

    session

    The session ID for the OTP.

    policyValidation

    Whether to validate the password policy before sending the request to server.

    completion

    Completion block to be called after either register and sign in is complete or errors occurred.

  • Sign user in with Touch ID or Face ID.

    Declaration

    Swift

    @objc
    public static func signInWithBiometrics(completion: @escaping (NSError?) -> Void)
    Parameters
    completion

    Completion block to be called after either sign in is complete or errors occurred.

  • Sign the current user out.

    Declaration

    Swift

    @objc
    public static func signOut(completion: @escaping (NSError?) -> Void)
    Parameters
    completion

    Completion block to be called after sign out is complete or errors occured.

  • Fetch the current user information from server.

    Declaration

    Swift

    @objc
    public static func fetchUser(completion: @escaping (User?, NSError?) -> Void)
    Parameters
    completion

    Completion closure that will be called after fetching user info.

  • Update user info to server. Note that the fields userId and uid do not need to be provided and any value provided in the user parameter will be ignored.

    Declaration

    Swift

    @objc
    public static func updateUser(user: User, completion: @escaping (User?, NSError?) -> Void)
    Parameters
    user

    Updated user information.

    completion

    Completion closure that will be called after fetching user information.

  • Update user contact info to server after OTP is verified successfully.

    Declaration

    Swift

    @objc
    public static func updateUserContactInfo(mobile: String,
                                             session: String,
                                             completion: @escaping (NSError?) -> Void)
    Parameters
    mobile

    A new mobile number which was already verified with OTP.

    session

    The session ID from OTP verification.

    completion

    Completion closure that will be called after updating user contact information.

  • Check user existence.

    Declaration

    Swift

    @available(*, deprecated, message: "Use checkForExistingUser(withId userId: String, completion:﹚ instead")
    @objc
    public static func checkExistence(userId: String,
                                      completion: @escaping (Bool, NSError?) -> Void)
    Parameters
    userId

    user identifier.

    completion

    Completion that will be called with tuple of a boolean and and an error object. The boolean indicates the existence of a user with the provided user ID.

  • Check user existence.

    Declaration

    Swift

    @objc
    public static func checkForExistingUser(withId userId: String,
                                            completion: @escaping (ExistingUser?, NSError?) -> Void)
    Parameters
    userId

    User identifier.

    completion

    Completion that will be called with tuple of a ExistingUser model object and an error object.

  • Fetch latest access token from server.

    Declaration

    Swift

    @objc
    public static func fetchToken(_ completion: @escaping (String?, NSError?) -> Void)
    Parameters
    completion

    Completion block to be called fetch token is complete or error occured.

  • Notify SDK to keep the session active after app relaunced.

    Declaration

    Swift

    @objc
    public static func keepMeSignIn(_ completion: @escaping (NSError?) -> Void)
    Parameters
    completion

    Completion block to be called execution is complete or error occured.

  • Enable Biometric Login.

    Declaration

    Swift

    @objc
    public static func enableBiometricsSignIn(_ completion: @escaping (NSError?) -> Void)
    Parameters
    completion

    Completion block to be called after enabling is complete or error occured.

  • Delete the currently logged in user.

    Declaration

    Swift

    @objc
    public static func deleteUser(completion: @escaping (NSError?) -> Void)
    Parameters
    completion

    Completion block to be called after deletion is complete or if an error occured.

  • Fetch the account policy from server.

    Declaration

    Swift

    @objc
    public static func fetchAccountPolicy(completion: @escaping (AccountPolicy?, NSError?) -> Void)
    Parameters
    completion

    Completion block to be called after the account policy is fetched or if an error occured.

  • Update the app code settings.

    Throws

    • .invalidInput
    Declaration

    Swift

    @objc
    public static func updateAppCodeSettings(enabled: Bool,
                                             appCode: String? = nil,
                                             completion: @escaping (NSError?) -> Void)
    Parameters
    enabled

    whether the app code is enabled.

    appCode

    the app code to be verified.

    completion

    Completion block to be called after the app code settings are updated or if an error occured.

  • Fetch the app code settings from the server.

    Throws

    • .invalidInput
    Declaration

    Swift

    @objc
    public static func fetchAppCodeSettings(completion: @escaping (AppCodeSettings?, NSError?) -> Void)
    Parameters
    completion

    Completion block to be called after the app code settings is fetched or if an error occured.

  • Get the cached app code settings.

    Declaration

    Swift

    @objc
    public static func getCachedAppCodeSettings() -> AppCodeSettings?
  • Verify the app code from the server.

    Throws

    • .invalidInput
    Declaration

    Swift

    @objc
    public static func verifyAppCode(_ appCode: String,
                                     fromServer: Bool = true,
                                     completion: @escaping (NSError?) -> Void)
    Parameters
    appCode

    The app code to be verified.

    fromServer

    Whether to verify the app code from the server or local, the default value if true.

    completion

    Completion block to be called after the app code is verified or if an error occured.