Splunk MINT SDK for iOS (Legacy)

Splunk MINT SDK for iOS Developer Guide

Splunk MINT is no longer available for purchase as of January 29, 2021. Customers who have already been paying to ingest and process MINT data in Splunk Enterprise will continue to receive support until December 31, 2021, which is End of Life for all MINT products: App, Web Service (Management Console), SDK and Add-On.

Objective-C code example

This code example shows how to use the Splunk MINT SDK for iOS API with Objective-C.

#import "ViewController.h"

#import <SplunkMint/SplunkMint.h>

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
}


- (void)mintConfiguration {
    
    //To preserve resources, the MINT SDK can be configured to send data only over a WIFI connection
    [[Mint sharedInstance] enableFlushOnlyOverWiFi:YES];
    
    //To protect privacy, the MINT SDK can be disabled so that no mobile telemetry is reported
    [[Mint sharedInstance] enableUserOptOut:YES];
    
    //The MINT SDK will start a new session if the application has not been in the foreground for
    //the duration of the session interval
    //Default session interval is 60 seconds
    [[Mint sharedInstance] setSessionInterval:60];
    
    //In order to send NSLOG in crash reports, enableLogging must be set to true
    [[Mint sharedInstance] enableLogging:YES];
    
    //Set the number of NSLOG messages to send in the crash report
    [[Mint sharedInstance] setLogging:10];
    
    
    [[Mint sharedInstance] enableMintLoggingCache:YES];
    
    //Set some form of userIdentifier for this session
    [Mint sharedInstance].userIdentifier = @"splunk";
    
    //Set the applicationEnvironment, the available options are
    /*
     SPLAppEnvRelease
     SPLAppEnvStaging
     SPLAppEnvUserAcceptanceTesting
     SPLAppEnvTesting
     SPLAppEnvDevelopment
     */
    [[Mint sharedInstance] setApplicationEnvironment:SPLAppEnvDevelopment];
    
     //Disable crash reports
    [[Mint sharedInstance] disableCrashReporter];
    
    //Disable network monitoring
    [[Mint sharedInstance] disableNetworkMonitoring];
    
    //Selectively disable network monitoring on blacklisted url's
    [[Mint sharedInstance] addURLToBlackList:@"https://google.com"];
    
    //Breadcrumbs are only sent out in crash reports
    //Leave breadcrumbs throughout the source code to better debug the execution path
    [[Mint sharedInstance] leaveBreadcrumb:@"code inside mintConfiguration is executing"];
    
    //Clear all breadcrumbs that have been added
    [[Mint sharedInstance] clearBreadcrumbs];
    
    //Instantiating a MintLimitedExtraData object
    MintLimitedExtraData *extraData = [[MintLimitedExtraData alloc] init];
    
    //Populating a MintLimitedExtraData object with key and value
    [extraData setValue:@"value0" forKey:@"key0"];
    
    //Adding local MintLimitedExtraData to global extra Data
    //Global value's will be overwritten if there is a key clash
    //Global extra data is sent out with each data point
    [[Mint sharedInstance] addExtraData:extraData];
    
     //Add key and value to global extra data
    [[Mint sharedInstance] addExtraData:@"value1" forKey:@"key1"];
    
     //Removing key and value from global extra data
    [[Mint sharedInstance] removeExtraDataForKey:@"key1"];
    
    //Return hashmap of global extra data key and values
    [[Mint sharedInstance] extraData];
    
    //Return value in the global extra data for the key passed in if it is present
    [[Mint sharedInstance] extraDataForKey:@"key0"];
    
    //Clears global extra data
    [[Mint sharedInstance] removeAllExtraData];
    
}



- (void) mintInitialize {
    //Initialize the SDK to use the MINT Backend to transport data
    //Will start a new session if one is not active
    [[Mint sharedInstance] initAndStartSessionWithAPIKey:@"API_KEY"];
    
    //Initialize the SDK to directly send data to a Splunk instance using
    //HTTP Event Collector
    //Will start a new session if one is not active
    [[Mint sharedInstance] initAndStartSessionWithHECUrl:@"HEC_URL" token:@"HEC_TOKEN"];
}

- (void)logSession {
    
    //Will start a new session if one is not active
    [[Mint sharedInstance] startSession];
    
    //Will close the active session
    [[Mint sharedInstance] closeSession];
}

- (void)mintData {
    
    //Will return set remote settings
    [[Mint sharedInstance] getDevSettings];
    
    //Will return the UUID of this MINT installation
    [[Mint sharedInstance] getMintUUID];
    
    //Will return the sessionID of the current session
    [[Mint sharedInstance] getSessionID];
    
    //Will return a list of the blacklisted url's
    [[Mint sharedInstance] blacklistUrls];
    
    //Will return bool indicating if the SDK was initialized to use HEC as its transport mechanism
    [[Mint sharedInstance] isHTTPEventCollectorEnabled];
    
    //Will return bool indicating if the SDK was initialized in any way
    [[Mint sharedInstance] isInitialized];
    
    //Will return bool indicating if the SDK has an active session
    [[Mint sharedInstance] isSessionActive];
    
}

- (void) logView {
    
    //Creating a local instance of MintLimitedExtraData to pass into our api calls
    MintLimitedExtraData *extraData = [[MintLimitedExtraData alloc] init];
    [extraData setValue:@"value0" forKey:@"key0"];

    /*
     Views are automatically collected in native environments. For all other use cases we have 3 API calls to log
     custom views. The difference in the API calls are variations on how to pass in extra data.
     */
    [[Mint sharedInstance] logViewWithCurrentViewName:@"ViewName"];
    [[Mint sharedInstance] logViewWithCurrentViewName:@"ViewName" extraDataKey:@"value2" extraDataValue:@"key2"];
    [[Mint sharedInstance] logViewWithCurrentViewName:@"ViewName" extraData:extraData];
}

- (void) logTransaction {
    //Creating a local instance of MintLimitedExtraData to pass into our api calls
    MintLimitedExtraData *extraData = [[MintLimitedExtraData alloc] init];
    [extraData setValue:@"value0" forKey:@"key0"];
    
    /*
     Transactions are manually started through API calls.  Transactions have three separate END states:
     SUCCESS: The transaction was stopped normally through a transactionStop API Call
     CANCEL: The transactionw was cancelled, the API requires a reason for canceling a transaction
     FAIL: Active transactions are automatically failed when an exception crashes the application.
     
     For each API there are 3 variations based on the extra data being passed in.
     */
    
    //Starting 3 transactions
    NSString *transactionId1 = [[Mint sharedInstance] transactionStart:@"transaction1"];
    NSString *transactionId2 = [[Mint sharedInstance] transactionStart:@"transaction2" extraDataKey:@"key1" extraDataValue:@"value1"];
    NSString *transactionId3 = [[Mint sharedInstance] transactionStart:@"transaction3" extraData:extraData];
    
    //Stopping 3 transactions, will have status=SUCCESS
    [[Mint sharedInstance] transactionStop:transactionId1];
    [[Mint sharedInstance] transactionStop:transactionId2 extraDataKey:@"key1" extraDataValue:@"value1"];
    [[Mint sharedInstance] transactionStop:transactionId3 extraData:extraData];
    
    //Starting 3 transactions
    transactionId1 = [[Mint sharedInstance] transactionStart:@"transaction1"];
    transactionId2 = [[Mint sharedInstance] transactionStart:@"transaction2" extraDataKey:@"key1" extraDataValue:@"value1"];
    transactionId3 = [[Mint sharedInstance] transactionStart:@"transaction3" extraData:extraData];

    //Cancelling 3 transactions, will have status=CANCEL
    [[Mint sharedInstance] transactionCancel:transactionId1 reason:@"bad_transaction"];
    [[Mint sharedInstance] transactionCancel:transactionId2 reason:@"bad_transaction" extraDataKey:@"key1" extraDataValue:@"value1"];
    [[Mint sharedInstance] transactionCancel:transactionId3 reason:@"bad_transaction" extraData:extraData];
    
}



- (void)logEvent {
    //Creating a local instance of MintLimitedExtraData to pass into our api calls
    MintLimitedExtraData *extraData = [[MintLimitedExtraData alloc] init];
    [extraData setValue:@"value0" forKey:@"key0"];
  
    /*
     The logEvent API calls can be used to log notable events.
     There are 4 variations based on the extra data being passed in and the log level to display.
     The following are allowed log levels
     
     MintLogLevel:
     
     DebugLogLevel
     InfoLogLevel
     NoticeLogLevel
     WarningLogLevel
     ErrorLogLevel
     CriticalLogLevel
     AlertLogLevel
     EmergencyLogLevel
     */

    [[Mint sharedInstance] logEventWithName:@"eventName"];
    [[Mint sharedInstance] logEventWithName:@"eventName" logLevel:DebugLogLevel];
    [[Mint sharedInstance] logEventWithName:@"eventName" logLevel:DebugLogLevel extraDataKey:@"key1" extraDataValue:@"value1"];
    [[Mint sharedInstance] logEventWithName:@"eventName" logLevel:DebugLogLevel extraData:extraData];
}

- (void)mintLog {
    MintLog(DebugLogLevel, @"LogIn");
}

- (void)mintException {
    //Creating a local instance of MintLimitedExtraData to pass into our api calls
    MintLimitedExtraData *extraData = [[MintLimitedExtraData alloc] init];
    [extraData setValue:@"value0" forKey:@"key0"];
  
    @try {
        NSArray *ids = @[@"1", @"2"];
        NSLog(@"%@", ids[2]);
        
    }
    @catch (NSException *exception) {
        
        //The logException API calls can be used to log handled exceptions.
        //For each API there are 3 variations based on the extra data being passed in.
        [[Mint sharedInstance] logException:exception];
        [[Mint sharedInstance] logException:exception extraDataKey:@"key1" extraDataValue:@"value1"];
        [[Mint sharedInstance] logException:exception extraData:extraData];
        
        MintLogException(exception, extraData);
    }
    
}

-(void)mintTimer {
    
    // The timer API calls can be used to create a high-precision timer in nanoseconds
    NSString* timerId1 = [[Mint sharedInstance] startTimerWithName:@"timer1"];
    [[Mint sharedInstance] stopTimerWithId:timerId1];
    
    NSString* timerId2 = [[Mint sharedInstance] startTimerWithName:@"timer2"];
    [[Mint sharedInstance] stopTimerWithId:timerId2];
}

- (void)mintMethodInvocation {
    
    //The trace Macro API calls can be used to log trace informations on specific method
    MINT_METHOD_TRACE_START
     // Do somthing
    MINT_METHOD_TRACE_STOP
    
    // if you are not using ARC, please use NON ARC API to stop the trace
    //MINT_NONARC_METHOD_TRACE_STOP
    
}

- (void)mintFlushData {
     //Flush all data currently in memory and in the filesystem
    [[Mint sharedInstance] flush];
}

@end
Last modified on 05 November, 2019
Monitor the battery level of devices   Swift code example

This documentation applies to the following versions of Splunk MINT SDK for iOS (Legacy): 5.2.x


Was this topic useful?







You must be logged into splunk.com in order to post comments. Log in now.

Please try to keep this discussion focused on the content covered in this documentation topic. If you have a more general question about Splunk functionality or are experiencing a difficulty with Splunk, consider posting a question to Splunkbase Answers.

0 out of 1000 Characters