setExpiryTime function not available in iOS Mobile Authenticator SWIFT SDK
search cancel

setExpiryTime function not available in iOS Mobile Authenticator SWIFT SDK

book

Article ID: 386748

calendar_today

Updated On:

Products

CA Strong Authentication CA Advanced Authentication CA Advanced Authentication - Strong Authentication (AuthMinder / WebFort)

Issue/Introduction

To extend the account expiration date from client side, otpAcc.setExpiryTime() function is not available in iOS Mobile Authenticator SWIFT SDK.

Environment

Symantec Strong Authentication 9.1.5.1

CA Mobile Authenticator iOS SDK 2.2.2

Resolution

Below is the recommended approach and sample code that can be used to update the expiration time in a custom function:

  • Call the getAllAccounts() API
  • Initialize the NumOfYears=10 for ex: here 10 years - customer can change this number
  • Loop all the accounts and set the time what customer need here NumOfYears=10
  • Use below code snipt to update exiting account.

(void)updateAccountExpiry {
   @try {
       NSArray<AuthAccount *> *listAccs = [(MainActivity *)self.activity getAuthenticator].getAllAccounts;
       
       NSInteger numOfYears = 10; // Number of years to extend the account expiry from current date
       
       for (NSInteger i = 0; i < listAccs.count; i++) {
           OTPAuthCredential *otpAcc = listAccs[i].otpAuthCredential;
           NSTimeInterval time = otpAcc.expiryTime;
           
           if (time <= [[NSDate date] timeIntervalSince1970]) {
               NSDate *currentDate = [NSDate date];
               NSDate *newExpiryDate = [currentDate dateByAddingTimeInterval:(numOfYears * 365.25 * 24 * 60 * 60)]; // Approx. 1 year in seconds

               otpAcc.expiryTime = [newExpiryDate timeIntervalSince1970];
               
               [(MainActivity *)self.activity.getAuthenticator saveAccount:listAccs[i].otpAccount];
           }
       }
   } @catch (AccountException *e) {
       NSLog(@"Error: %@", e.localizedDescription);
   }
}


Note: The variable name and function name may differ.