Strategy ONE

Customize the Login Screen UI and Input Parameters Programmatically for iOS

While it is possible to customize login screens without writing code, there may be instances where you need more granular control. For example, the login screen UI may need to match a very specific look and feel or authentication may require input parameters that are different from the ones provided in the non-programmatic approach. To meet requirements like these, you can customize the login screen programmatically, by extending the MSIMobileLoginPromptView class and assigning this custom subclass as the definition of the login view for the authentication prompts.

To customize authentication  programmatically:  

  1. Create a custom AppDelegate as described in Adding functionality with a custom application delegate.  

  2. Create a new Objective-C class that is a subclass of MSIMobileLoginPromptView and add it to the desired targets.


  3. Override the -(void) setupWithParameters:(NSDictionary*) promptViewParameters delegate:(id<MSIMobileLoginPromptViewDelegate>) delegate; method.

    The promptViewParameters provides useful information that can be used in the custom login screen UI. This includes values such as the project information, as well as label values defined in the MSIAuthenticationSettings.plist.

    A typical implementation of this method would look like the code snippet below: 

    Copy
    - (void) setupWithParameters:(NSDictionary*) promptViewParameters delegate:(id<MSIMobileLoginPromptViewDelegate>) delegate{
        [super setupWithParameters:promptViewParameters delegate:delegate]; 
        //After calling super, add additional code to setup the login UI, for example, add textfields, login buttons, background image 
    }
  4. Implement the loginPromptView:didInputAuthenticationParameters method of the view’s delegate, which lets the delegate know that the user has inputted the authentication parameters.

    This would typically be done in a method triggered by a login button. The authentication parameters are a dictionary that must contain the user name and password, as well as the list of custom parameters that are passed to the mobile login task for validation. The structure of the dictionary is defined as follows:

    Copy
    @{“username”:<user name value as string>,“password”:<password as string>,“customparameter1”:<custom parameter 1 as string>,“custom parameter2”:<custom parameter 2 as string>,“customparametern”:<custom parameter n as string>}

    The following is a code snippet of a method called login, which would be called by a login button. This code snippet assumes that only the user name and password are used for authentication and that those values are captured in the usernameTextField and passwordTextField text fields.

    Copy
    -(void) login{
        [self.delegate loginPromptView:self didInputAuthenticationParameters:@{
             @"username":([usernameTextField text]?[usernameTextField text]:EMPTY_STRING),
             @"password":([passwordTextField text]?[passwordTextField text]:EMPTY_STRING)
        }];
    }
  1. Implement the loginPromptViewDidCancel method of the view’s delegate which lets the delegate know that the user has tapped on the Cancel button of the login screen. This would typically be done in a method triggered by a Cancel button. The following code snippet illustrates a sample cancel method implementation:

    Copy
    -(void) cancel{
        [self.delegate loginPromptViewDidCancel:self];
    }
  1. Register the custom login view class in the MSIMobileLoginManager so that it is used for the prompt type for which it was designed.

    This is done in the application:didFinishLaunchingWithOptions method of the AppDelegate, using the setView:controller:module:forPromptType API defined in the MSIMobileLoginManager class. The following code snippet registers a custom view to be used with the authentication prompt:

    Copy
    //
    //  CustomAppDelegate.m
    //  MicroStrategyMobile
    //
    //  Copyright (c) 2014 MicroStrategy Inc. All rights reserved.
    //
    #import "CustomAppDelegate.h"
    #import "CustomLoginView.h"
    #import <MicroStrategyMobileSDK/MSIAuthenticationModule.h>
    #import <MicroStrategyMobileSDK/MSIAuthenticationPromptViewController.h>
    #import <MicroStrategyMobileSDK/MSIMobileLoginManager.h>
    #import <MicroStrategyMobileSDK/MSIProjectInfo.h>
    @implementation CustomAppDelegate
    -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{    
        
        CustomLoginView *loginView = [[CustomLoginView alloc] initWithFrame:self.window.frame];
        MSIAuthenticationPromptViewController *loginViewController = [[MSIAuthenticationPromptViewController alloc] init];
        MSIAuthenticationModule *loginModule = [[MSIAuthenticationModule alloc] init];
        [[MSIMobileLoginManager sharedMobileLoginManager] setView:loginView controller:loginViewController module:loginModule forPromptType:AuthenticationPromptType];
        
        BOOL res = [super application:application didFinishLaunchingWithOptions:launchOptions];
        return res;
    }
    @end
  1. Validate the custom parameters passed to the mobile server.

    Validation has to be performed by implementing a custom mobile login task.