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.

Swift code example

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

import UIKit
//Importing the Splunk MINT SDK
import SplunkMint

class ViewController: UIViewController {

    func mintConfiguration() {
        //To preserve resources, the MINT SDK can be configured to send data only over a WIFI connection
        //To protect privacy, the MINT SDK can be disabled so that no mobile telemetry is reported
        //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
        //In order to send NSLOG in crash reports, enableLogging must be set to true
        //Set the number of NSLOG messages to send in the crash report
        //Set some form of userIdentifier for this session
        Mint.sharedInstance().userIdentifier = "splunk"
        //Set the applicationEnvironment, the available options are
        Mint.sharedInstance().applicationEnvironment = SPLAppEnvDevelopment
        //Disable crash reports
        //Disable network monitoring
        //Selectively disable network monitoring on blacklisted url's
        //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
        //Instantiating a MintLimitedExtraData object
        let myExtraData = MintLimitedExtraData()
        //Populating a MintLimitedExtraData object with key and value
        myExtraData.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
        //Add key and value to global extra data
        Mint.sharedInstance().addExtraData("Value1", forKey: "Key1")
        //Removing key and value from global extra data
        //Return hashmap of global extra data key and values
        //Return value in the global extra data for the key passed in if it is present
        //Clears global extra data
    func mintInitialize() {
        //Initialize the SDK to use the MINT Backend to transport data
        //Will start a new session if one is not active
        //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")
    func logSession() {
        //Will start a new session if one is not active
        //Will close the active session
    func mintData() {
        //Will return set remote settings
        //Will return the UUID of this MINT installation
        //Will return the sessionID of the current session
        //Will return a list of the blacklisted url's
        //Will return bool indicating if the SDK was initialized to use HEC as its transport mechanism
        //Will return bool indicating if the SDK was initialized in any way
        //Will return bool indicating if the SDK has an active session
    func logView() {
        //Creating a local instance of MintLimitedExtraData to pass into our api calls
        let myExtraData = MintLimitedExtraData()
        myExtraData.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", extraDataKey: "Key1", extraDataValue: "Value1")
        Mint.sharedInstance().logViewWithCurrentViewName("ViewName", extraData: myExtraData)

    func logTransaction() {
        //Creating a local instance of MintLimitedExtraData to pass into our api calls
        let myExtraData = MintLimitedExtraData()
        myExtraData.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
        var transactionId1 = Mint.sharedInstance().transactionStart("transaction1")
        var transactionId2 = Mint.sharedInstance().transactionStart("transaction2", extraDataKey: "Key1", extraDataValue: "Value1")
        var transactionId3 = Mint.sharedInstance().transactionStart("transaction3", extraData: myExtraData)
        //Stopping 3 transactions, will have status=SUCCESS
        Mint.sharedInstance().transactionStop(transactionId2, extraDataKey: "Key1", extraDataValue: "Value1")
        Mint.sharedInstance().transactionStop(transactionId3, extraData: myExtraData)
        //Starting 3 transactions
        transactionId1 = Mint.sharedInstance().transactionStart("transaction1")
        transactionId2 = Mint.sharedInstance().transactionStart("transaction2", extraDataKey: "Key1", extraDataValue: "Value1")
        transactionId3 = Mint.sharedInstance().transactionStart("transaction3", extraData: myExtraData)
        //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: myExtraData)
        // There are also failed transactions, these are sent out automatically when the MINT SDK detects an
        //unhandled exception while a transaction is still in progress
        //transactionId1 = Mint.sharedInstance().transactionStart("transaction1")
        //transactionId2 = Mint.sharedInstance().transactionStart("transaction2", extraDataKey: "Key1", extraDataValue: "Value1")
        //transactionId3 = Mint.sharedInstance().transactionStart("transaction3", extraData: myExtraData)
        //let myArray = []


    func logEvent() {
        //Creating a local instance of MintLimitedExtraData to pass into our api calls
        let myExtraData = MintLimitedExtraData()
        myExtraData.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
        Mint.sharedInstance().logEventWithName("eventnName", logLevel: DebugLogLevel)
        Mint.sharedInstance().logEventWithName("eventName", logLevel: DebugLogLevel, extraDataKey: "Key1", extraDataValue: "Value1")
        Mint.sharedInstance().logEventWithName("eventName", logLevel: DebugLogLevel, extraData: myExtraData)

    func mintTimer() {
        // The timer API calls can be usedd to create a high-precision timer in nanoseconds
        let timerId = Mint.sharedInstance().startTimerWithName("timer1")

    func mintFlushData() {
        //Flush all data currently in memory and in the filesystem
Last modified on 05 November, 2019
Objective-C code example   API Reference

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