Skip to content

Device Re-registration

iOS SDK provides featured to re-register device and use BSA SDK by using basic information.

i. User Information Verification & OTP Number Request

userKey, name, verifyDatamust all be valid for OTP to be sent. In all other cases, it will report an error through onFailed. The LocalAuthType received on success represents the Local Authentication Type last used by the user and must be authenticated before making a Register New Device request.

Example

swift
BSA.APICaller.requestSendOTPNumberForRegisterDevice(
										clientKey: "a1hrg2xv...",
										userKey: "user1",
										name: "username1",
										sendType: .Email,
										sendTarget: "user@email.com",
										bundleIdentifier: "com.your.app",
onSuccess: { [weak self] localAuthType in
	// Successful Invocation
	
	// Local Authentication Type of Registered User
	self?.data.existingUserData?.authType = localAuthType

}, onFailed: { [weak self] rtCode, resultMessage in

	// Invocation Failure

}, onError: { [weak self] error in

	// Invocation Error

}, onTotalLog: { text in

	// Invocation Log

}, onCompleted: { 

	// invocation completed

}, disposeBag: disposeBag)

BSA.APICaller.requestSendOTPNumberForRegisterDevice

swift
BSA.APICaller.requestSendOTPNumberForRegisterDevice(
						clientKey:String,
						userKey: String, 
						name: String,
						sendType: BSA.APICaller.OTPSendType, 
						sendTarget: String,
						bundleIdentifier: String,
						onSuccess: @escaping (BSA.Enums.LocalAuthType) -> (),
						onFailed: @escaping OnFailed, 
						onError: @escaping OnError, 
						onTotalLog: @escaping OnTotalLog? = nil,
						onCompleted: @escaping onCompleted? = nil,
						disposeBag: DisposeBag )

Parameter

ParameterTypeDescription
clientKeyStringClient's unique key
userKeyStringUserID
nameStringUser name
sendTypeBSA.APICaller.OTPSendTypeEmail, PhoneNumber
sendTargetStringAddress or number matching sendType
bundleIdentifierStringApp's bundleIdentifier
onSuccess(BSA.Enums.LocalAuthType) -> ()Callback called on success. It returns the last Local Authentication Type used by the user.
onFailedOnFailedCallback function called on API processing failure.
onErrorOnErrorCallback function called on error.
onTotalLogOnTotalLogCallback function to receive all logs generated during API calls.
onCompletedonCompletedCalled at the end after all processes are completed.
disposeBagDisposeBagDisposeBag variable to manage RxSwift Disposable objects.

ii. OTP Number Validation

Enter the OTP number received by email/sms, call the API, and if successful, receive the disposeToken string. disposeToken is used to check whether the user is the correct user during Register New Device.

Example(BSA.APICaller.verifyOTPNumber

swift
BSA.APICaller.verifyOTPNumber(sendType: BSA.APICaller.OTPSendType, 
							  sendTarget: String,
							  otpNumber: "298336", 
							  clientKey: "a1hrg2xv...",
onValidOTPNumber: { [weak self] disposeToken in

	// OTP Number Matches
             
	// Token Storage
	self?.data.disposeToken = disposeToken

}, onInvalidOTPNumber: {

	// OTP Number Doesn't Match
                
}, onFailed: { [weak self] rtCode, resultMessage in

	// Invocation Failure

}, onError: { [weak self] error in

	// Invocation Error

}, onTotalLog: { text in

	// Invocation Log

}, onCompleted: { 

	// invocation completed

}, disposeBag: disposeBag)
swift
BSA.APICaller.verifyOTPNumber(sendType: BSA.APICaller.OTPSendType, 
							  sendTarget: String, 
							   otpNumber: String, 
							   clientKey: String,
							   onValidOTPNumber: @escaping (String) -> (),
							   onInvalidOTPNumber: @escaping () -> (),
							   onFailed: @escaping OnFailed, 
							   onError: @escaping OnError, 
							   onTotalLog: @escaping OnTotalLog? = nil,
							   onCompleted: @escaping onCompleted? = nil,
							   disposeBag: DisposeBag )

Parameter

ParameterTypeDescription
sendTypeBSA.APICaller.OTPSendTypePlatform to receive OTP number (Email, SMS)
sendTargetStringAddress for OTP number type
otpNumberStringReceived OTP number.
clientKeyStringClient's unique Key
onValidOTPNumber(String) -> ()Callback called when OTP numbers match. The disposeToken value passed as a parameter is used in SignUp.
onInvalidOTPNumber() -> ()Callback called when OTP numbers don't match.
onFailedOnFailedCallback function called on API processing failure.
onErrorOnErrorCallback function called on error.
onTotalLogOnTotalLogCallback function to receive all logs generated during API calls.
onCompletedonCompletedCalled at the end after all processes are completed.
disposeBagDisposeBagDisposeBag variable to manage RxSwift Disposable objects.

iii. Local Authentication

When called, it performs biometric and passcode authentication. For Register New Device, there is no saved DomainState for biometric authentication, so checkDomainStateChanged should be set to false.

Local Authentication must succeed to invoke BSA.APICAller.requestSignUp. The callback called with onResult runs on a background thread, so UI operations should be done on the main thread.

Example

swift
BSA.LocalAuth.startSimpleAuth(localAuthType: .BIOMETRIC,
							  reason: "Authentication is required to verify your identity",
							  checkDomainStateChanged: false,
							  usePasscodeWhenFailed: false,
onSuccess: {

	// onSuccess operates on a background thread, so UI-related tasks should be performed on the main thread.
	DispatchQueue.main.async {

		// Local Authentication Successful

	}

}, onError: { errorCode in
			 
	// onError operates on a background thread, so UI-related tasks should be performed on the main thread.
	DispatchQueue.main.async {

		// Local Authentication Failed

		switch errorCode {
		case .DOMAIN_STATE_CHANGED:
			// Biometric authentication info has been changed
		case .BIOMETRIC_NOT_AVILABLE
		case .BIOMETRIC_NOT_SUPPORT_HARDWARE
		case .BIOMETRIC_LOCK_OUT:
			// Biometric authentication not available
		case .BIOMETRIC_NOT_ENROLLED_DEVICE:
			// Biometric authentication info is not on device
		case .PASSCODE_NOT_ENROLLED_DEVICE:
			// Passcode not on device
		case .USER_CANCEL, .USER_FALLBACK:
			// User cancels authentication
		case .AUTH_FAILED:
			// Authentication failed
		default:
			// Other errors
		}

	}

})

BSA.LocalAuth.startSimpleAuth

swift
BSA.LocalAuth.startSimpleAuth(
						localAuthType: BSA.Enums.LocalAuthType, 
						reason: String,
						checkDomainStateChanged: Bool, 
						usePasscodeWhenFailed: Bool, 
						onSuccess: @escaping ()->(), 
						onError: @escaping (BSA.LocalAuthHelper.ErrorCode?)->())

Parameter

ParameterTypeDescription
localAuthTypeBSA.Enums.LocalAuthTypeLocal authentication type
reasonStringMessage displayed on OS during biometric authentication
checkDomainStateChangedBoolDetermine whether to detect biometric changes
usePasscodeWhenFailedBoolDecide whether to use a passcode when biometric authentication fails
onSuccess()->()Local authentication processing result callback
onError(BSA.LocalAuthHelper.ErrorCode?)->()Local authentication processing result callback

iv. Register New Device

existingUserData must be filled with complete data when making the call.

Example

swift
BSA.APICaller.requestRegisterDevice(existingUserData: data.existingUserData!,
onSuccess: {
	// Successful Device Re-registration

}, onFailed: { [weak self] rtCode, resultMessage in

	// Invocation Failure

}, onError: { [weak self] error in

	// Invocation Error

}, onTotalLog: { text in

	// Invocation Log

}, onCompleted: { 

	// invocation completed

}, disposeBag: disposeBag)

Parameter

swift
BSA.APICaller.requestRegisterDevice(
						existingUserData: BSA.SignUpData.ExistingUserData,
						onSuccess: @escaping () -> (),
						onFailed: @escaping OnFailed, 
						onError: @escaping OnError, 
					    onTotalLog: @escaping OnTotalLog? = nil,
					    onCompleted: @escaping onCompleted? = nil,
						disposeBag: DisposeBag )
ParameterTypeDescription
existingUserDataBSA.SignUpData.ExistingUserDataData required for Register New Device. Fill all fields and make the call.
onSuccess() -> ()Callback called on Register New Device success.
onFailedOnFailedCallback function called on API processing failure.
onErrorOnErrorCallback function called on error.
onTotalLogOnTotalLogCallback function to receive all logs generated during API calls.
onCompletedonCompletedCalled at the end after all processes are completed.
disposeBagDisposeBagDisposeBag variable to manage RxSwift Disposable objects.

BSA.SignUpData.ExistingUserData

NameTypeDescription
appPackageStringBundleIdentifier
clientKeyStringClient's unique key
appVersionStringApp version (e.g., 1.1.1)
tokenStringFCM token value.
emailStringEmail address.
phoneNumberStringPhone number.
userKeyStringUserID
nameStringUser name
authTypeBSA.Enums.LocalAuthTypeLocal Authentication Type (NONE, BIOMETRIC, PASSCODE)
osBSA.Enums.OSTypeos type (fixed to iOS)
disposeTokenStringToken received upon OTP authentication success.
otpTypeBSA.Enums.OTPTypeType of OTP number received (email, SMS).

Information saved after Register New Device

If Register New Device is successful, you can retrieve information using the following functions. BSA.loadTOTPSecretKey BSA.loadDeviceID BSA.loadFCMToken BSA.loadUserKey BSA.loadLocalAuthType