Session Management
Sign In
Sign In with Username and Password
AccountManager.signIn(userId: email, password: password) { [weak self] (error) in
if let error = error {
NotificationUI.showMessage(type: .error, title: "Error", message: error.localizedDescription)
} else {
AccountManager.fetchUser(completion: { (user, error) in
if let _ = error {
//error handling
} else {
if let user = user {
//do more thing
}
}
})
}
}
Keep Me Signed In
In the signIn method, there is a keepMeSignIn param that indicates whether the SDK should serialize the session to a keychain. If this is set to true, the session is restored the next time the app is launched.
public static func signIn(userId: String,
password: String,
keepMeSignIn: Bool = false,
completion: @escaping (UsherErrorProtocol?) -> Void)
If the keepMeSignIn param is set to false during sign in, the client can still call the method shown below to enable keepMeSignIn later:
public static func keepMeSignIn(_ completion: @escaping (UsherErrorProtocol?) -> Swift.Void)
Sign In with Biometrics
Use the enableBiometricsSignIn method to allow users to sign in with biometrics. You must disable Keep Me Signed In to use this functionality. After sign in, the client code invokes the method shown below to enable biometric sign in.
AccountManager.enableBiometricsSignIn {[weak self] (error) in
if error != nil {
NotificationUI.showMessage(type: .error,
title: "Failed to enable Biometric Login",
message: error!.localizedDescription)
} else {
NotificationUI.showMessage(type: .success,
title: "Biometric Login",
message:"You can use Biometric login after app restarted.")
}
//continue to app logic
}
To trigger biometric login, make sure AccountManager.isBiometricsSignInEnabled
is set to true before calling the AccountManager.signInWithBiometrics(completion:)
API.
if AccountManager.isBiometricsSignInEnabled {
AccountManager.signInWithBiometrics { [weak self] (error) in
}
}
If AccountManager.isBiometricsSignInEnabled is set to true, the biometric authentication process is triggered. After the user provides valid biometric information, the session can be restored.
Sign Out
To sign out the current user, call the method shown below.
AccountManager.signOut { [weak self] (error) in
//do more thing
}