Version 2021

Log On: Create and Use Sessions in iOS

When you run a MicroStrategy report in a mobile application, logon takes place automatically. If there is an existing session, it is used; if no session exists, a new session is created using the information in the preferences file. However, in some instances, you may want to retrieve the current session so that you can reuse it for other tasks, such as writeback.

The code snippets below illustrate how to create and use MicroStrategy sessions from a mobile application.

  • Setting up preferences

    To set up preferences, you can call the MSIGeneric setupConnectInfoFromPlist: method, which reads the connection information stored in the ConnectionInfo.plist file and gets the user preferences. Alternatively, you can use the code snippet shown below to have more control over what you save.

    Copy
    MSIPreferencesStore* store = [MSIPreferencesStore preferencesStore];
    MSIDevicePreferences *dp = [store preferencesCopy];
    WebServerList* wsl = [dp getWebServers];
    MSIProjectConfiguration* project = [MSIProjectList newProjectConfiguration];
    WebServerConfiguration* wsc = [WebServerList newWebServerConfiguration];
     
    // configure this project
    project.projectName = projectName;
    project.serverName = iserver;
    project.serverPort = [port intValue];
    project.credentials.login = uid;
    project.credentials.password = pwd;
    project.credentials.authMode = [MSIGeneric authenticationModeForString:projAuthMode];
     
    // add this project to web server
    [wsc.projects add:project];
    [project release];
     
    // configure this web server
    wsc.name = webServer;
    wsc.port = [webPort intValue];
    wsc.path = path;
    wsc.credentials.authMode = [Generic webAuthenticationModeForString:webAuthMode];
    wsc.credentials.login = webUID;
    wsc.credentials.password = webPwd;
     
    if ([appType caseInsensitiveCompare:@"J2EE"] == NSOrderedSame ) {
       wsc.type = J2EE;
    } else if ([appType caseInsensitiveCompare:@"ASP"] == NSOrderedSame){
       wsc.type = DOTNET;
    }
     
    // add this web server to web server list
    [wsl add:wsc];
    [wsc release];
     
    // save the above configuration to preferences store
    [store storePreferences:dp];
    [dp release];

    The following code snippet uses the connection information to get the project containing the report to be executed. First, it searches the list of web servers for the web server specified in the user preferences. Next, it searches the projects in the web server to find the project specified in the user preferences.

    Copy
    WebServerList *wsl1 = [[[MSIPreferencesStore preferencesStore] masterPreferences] getWebServers];
    WebServerConfiguration *wsc1 = [wsl1 getWebServer:0];
    MSIProjectList *pl = [wsc1 projects];
    MSIProjectInfo *pi = [[pl getProject:0] copyProjectInfo];

    Finally, it searches the reports in the project to find the report specified in the code. The following code snippet gets the report using the report ID. 

    Copy
    NSString *reportID = @"846195254BFF1196C93BC491B0F5B046";
    MSILiveReportInfo *report = [[ReportStore getReportStore] newLiveReport:reportID    type:ObjectTypeReportDefinition projectInfo:pi];
  • Creating a session automatically when a report is run

    When a report is executed, the SDK implicitly calls the mobileLogin task, which uses this connection information and the user id and password to create a session. Refer to Customizing Authentication for an explanation of how to customize the mobileLogin task.

  • Retrieving a session for reuse

    To retrieve a session, you use the same ProjectInfo object you got when you ran the live report.

    Copy
    NSString* sessionState = [[MSIServiceFactory getServiceFactory] getSessionState:pi];