Skip to content

iOS SDK Integration ​

Integration guide for the SmartOTP iOS SDK, distributed as CakeOTP.xcframework.

WARNING

This page documents the iOS SDK's parameters, results and error codes. Ask CAKE Support for the header files or a sample project for exact method signatures before implementing.

Install ​

  1. Open your Xcode project.
  2. Drag CakeOTP.xcframework into the project.
  3. Tick Copy items if needed, Create groups, and Add to targets.
  4. Select your project target.
  5. Under Frameworks, Libraries, and Embedded Content, set the framework to Embed & Sign.
  6. Import CakeOTP in your code.

Configure ​

ParamTypeRequiredDefaultDescription
hostNameStringNoGenerated by the SDKThe API host name.
isShowLogBoolNofalsePrint SDK logs.
Timeout intervalIntNo30HTTP request timeout in seconds.

Custom headers are added by initialising a RestEntity object and calling its add function — available both directly and through the update-configurations function.

Overriding the base URL ​

Every API service accepts an overrideBaseUrl parameter.

WARNING

Passing null or an empty string for overrideBaseUrl does not fall back to hostName — the request fails with Unknown host name. Omit the parameter rather than passing an empty value.

Activate ​

ParamTypeRequiredDefaultDescription
otpStringYes—The OTP sent by the server after your backend called Register.
vpBankUserIdStringNoGenerated by the SDKThe user id.
vpBankDeviceIdStringNoGenerated by the SDKThe device id.
vpBankPartnerIdStringNoGenerated by the SDKThe partner id.
deviceOSStringNoiOSDevice OS for tracking.
pushTokenStringNo—Push token, if used.
appVersionStringNo—App version, if used.
tokenStringNo—The registration token from Register.
registrationIdStringNo—The registration id from Register.

Returns: ActivateSOTPModel, or a CakeErrorModel carrying code and message.

The otp parameter is the activation_key from the Register response.

CodeDescription
3Parameter invalid
103Thông tin Partner không chính xác — Partner details are incorrect.
124OTP không hợp lệ — Invalid OTP.
125OTP hết hạn sử dụng — OTP expired.
129Token không hợp lệ — Invalid token.

INFO

The iOS parameters are named vpBankUserId, vpBankDeviceId and vpBankPartnerId. These are generic user, device and partner identifiers despite the tenant-specific naming — pass your own values regardless of which partner you are.

PIN and Storage ​

Store ​

ParamTypeRequiredDefaultDescription
pinStringYes—The user's PIN, 4 or 6 digits.
vpBankUserIdStringNoGenerated by the SDKThe user id.

Stores the Soft OTP secret in local storage inside the SDK, encrypted with the PIN.

Check ​

ParamTypeRequiredDefaultDescription
pinStringYes—The user's PIN, 4 or 6 digits.

Returns: Bool. Must be called only after storing the Soft OTP successfully.

Clear ​

Clears the currently stored PIN.

Change PIN ​

ParamTypeRequiredDefaultDescription
oldPinStringYes—The current PIN. Pass an empty string when there is no stored PIN.
newPinStringYes—The new PIN, checked against the two most recent PINs.

Returns: ChangePinResult

FieldTypeDescription
successChangePinResultThe PIN was changed.
invalidOldPinChangePinResultThe old PIN is not valid.
sameOldAndNewPinChangePinResultThe new PIN is identical to the old one.
samePreviousPinsChangePinResultThe new PIN matches one of the stored previous PINs.
unknownFailureChangePinResultAn unidentified error.

iOS distinguishes five outcomes where Android reports three — sameOldAndNewPin and samePreviousPins both surface as UNKNOWN_FAILURE on Android.

Generate OTP ​

Basic ​

Takes no parameters. Returns: String? — the generated basic Soft OTP.

Advance ​

ParamTypeRequiredDefaultDescription
challengeKeyStringYes—The challenge key from Create Transaction, hashed from user_id, device_id, registration_id, app_id, transaction_id, transaction_amount and unique_id with the server's private key.

Returns: String? — the generated advance Soft OTP.

Get Status ​

Returns: status as a String, or a CakeErrorModel.

One of NON_ACTIVATED, ACTIVATED, TEMPORARY_BLOCKED, NOT_CURRENT_USER, NOT_REGISTERED — see Mobile SDK Overview § Status Values.

CodeDescription
103Thông tin Partner không chính xác — Partner details are incorrect.

Sync Time ​

Returns the server's current timestamp as SyncTimeData, or a CakeErrorModel.

CodeDescription
103Thông tin Partner không chính xác — Partner details are incorrect.
129Token không hợp lệ — Invalid token.
190108Tài khoản chưa hoạt động — Account not activated.
190302OTP không chính xác — Incorrect OTP.

Retire ​

Deactivates the user's currently active Soft OTP.

Returns: Bool, or a CakeErrorModel.

CodeDescription
3Parameter invalid
103Thông tin Partner không chính xác — Partner details are incorrect.
129Token không hợp lệ — Invalid token.

Latest Transaction ​

Takes no parameters. Returns: LatestTransactionResponseModel, or a CakeErrorModel.

Equivalent to Get Latest Transaction.

Accessors ​

FieldTypeDescription
Get current usernameString?The registered username.
Get current registration_idString?The registered registration id.
Get current user idString?The registered user id.
Get serial idString?The serial id from the server.
Save serial id—Stores a serial id you supply yourself.
Get timeGetTimeResponseModelThe server timestamp, via the GetTime API.
Get periodInt?The TOTP period.
Get remaining validity timeIntSeconds left on the current OTP. Returns -1 on error.
Check is SOTP registeredBoolWhether this device has registered SmartOTP.

INFO

getRemainingValidityTime returns -1 on error on iOS, while Android returns an empty value. Check for -1 explicitly rather than treating any falsy result as zero.

Implementation Notes ​

WhatDescription
Method signaturesNot listed here. Exact names, argument labels and completion-handler shapes come with the header files from CAKE Support.
RestEntityReferenced for custom headers with no type definition given.
Error messagesShown here with Vietnamese diacritics. The SDK may return them without diacritics (Thong tin Partner khong chinh xac) — match on the code, not the text.

Next Steps ​

Developers