iOS SDK - Methods Reference

iOS SDK - Methods Reference

This comprehensive reference documents all available methods in the Singular SDK for iOS applications. The SDK provides functionality for initialization, event tracking, revenue reporting, attribution, data privacy compliance, and configuration. Each method is presented with a description, signature, and practical usage examples to help developers integrate Singular's SDK capabilities into their applications.

adRevenue

Singular.adRevenue Method

Tracks ad revenue events with detailed ad data information. This method allows you to report revenue generated from ads displayed in your application with various parameters to categorize and analyze the ad performance.

Signature

+ (void)adRevenue:(SingularAdData *)adData;

Usage Example

Swift Objective-C
// Create ad data object
let adData = SingularAdData(adPlatform: "AdMob", 
                            withCurrency: "USD", 
                            withRevenue: 0.05)
adData.adUnitId = "ca-app-pub-123456789/1234567890"
adData.adType = "Rewarded"
adData.adPlacementName = "level_complete"

// Track ad revenue event
Singular.adRevenue(adData)

clearGlobalProperties

Singular.clearGlobalProperties Method

Removes all previously set global properties. This is useful when you need to reset the global properties, for example when a user logs out of your application.

Signature

+ (void)clearGlobalProperties;

Usage Example

Swift Objective-C
// Clear all global properties
Singular.clearGlobalProperties()

createReferrerShortLink

Singular.createReferrerShortLink Methods

Creates a short link with referrer information that can be used for sharing and attribution. This method generates trackable links that can be shared with users, allowing you to attribute installs and activities to specific referral sources.

Signatures

+ (void)createReferrerShortLink:(NSString *)baseLink
                   referrerName:(NSString *)referrerName
                     referrerId:(NSString *)referrerId
              completionHandler:(void (^)(NSString *, NSError *))completionHandler;

+ (void)createReferrerShortLink:(NSString *)baseLink
                   referrerName:(NSString *)referrerName
                     referrerId:(NSString *)referrerId
              passthroughParams:(NSDictionary *)passthroughParams
              completionHandler:(void (^)(NSString *, NSError *))completionHandler;

Usage Example

Swift Objective-C
// Create a short link for referral
Singular.createReferrerShortLink("https://sample.sng.link/B4tbm/v8fp",
                                 referrerName: "John Doe",
                                 referrerId: "aq239897",
                                 passthroughParams: [
                                     "channel": "sms",
                                     "campaign": "summer_promo"
                                 ]) { link, error in
    if let error = error {
        print("Error creating short link: \(error)")
    } else if let link = link {
        print("Generated short link: \(link)")
        // Share the link with users
    }
}

customRevenue

Singular.customRevenue Methods

Tracks custom revenue events with a specified event name, currency, amount, and optional product information. This allows for more specific revenue tracking with custom event names.

Signatures

+ (void)customRevenue:(NSString *)eventname 
          transaction:(id)transaction;

+ (void)customRevenue:(NSString *)eventname 
          transaction:(id)transaction 
       withAttributes:(NSDictionary *)attributes;

+ (void)customRevenue:(NSString *)eventname 
             currency:(NSString *)currency 
               amount:(double)amount;

+ (void)customRevenue:(NSString *)eventname 
             currency:(NSString *)currency 
               amount:(double)amount 
       withAttributes:(NSDictionary *)attributes;

+ (void)customRevenue:(NSString *)eventname 
             currency:(NSString *)currency 
               amount:(double)amount 
           productSKU:(NSString *)productSKU 
          productName:(NSString *)productName 
      productCategory:(NSString *)productCategory 
      productQuantity:(int)productQuantity 
         productPrice:(double)productPrice;

+ (void)customRevenue:(NSData *)transactionJsonRepresentation
      productJsonRepresentation:(NSData *)productJsonRepresentation;

+ (void)customRevenue:(NSString *)eventName
      transactionJsonRepresentation:(NSData *)transactionJsonRepresentation
      productJsonRepresentation:(NSData *)productJsonRepresentation;

+ (void)customRevenue:(NSString *)eventName
      transactionJsonRepresentation:(NSData *)transactionJsonRepresentation
      productJsonRepresentation:(NSData *)productJsonRepresentation
      withAttributes:(NSDictionary *)attributes;

Usage Example

Swift Objective-C
// Track a custom revenue event
Singular.customRevenue("premium_subscription",
                       currency: "USD",
                       amount: 9.99)

// Track a custom revenue event with attributes
Singular.customRevenue("in_app_purchase",
                       currency: "USD",
                       amount: 5.99,
                       withAttributes: [
                           "product_id": "com.app.gems_pack_small",
                           "quantity": 1
                       ])

// Track a custom revenue event from a StoreKit transaction
if let transactionData = transaction.payment.requestData,
   let productData = try? JSONSerialization.data(withJSONObject: [
       "productID": transaction.payment.productIdentifier
   ]) {
    Singular.customRevenue("in_app_purchase",
                           transactionJsonRepresentation: transactionData,
                           productJsonRepresentation: productData,
                           withAttributes: ["source": "store"])
}

event

Singular.event Methods

Tracks events with the specified name and optional custom attributes. Use these methods to track user actions and engagement within your application.

Signatures

+ (void)event:(NSString *)name;

+ (void)event:(NSString *)name withArgs:(NSDictionary *)args;

+ (void)eventWithArgs:(NSString *)name, ...;

Usage Example

Swift Objective-C
// Track a simple event
Singular.event("level_completed")

// Track an event with additional parameters
Singular.event("level_completed", withArgs: [
    "level_id": 5,
    "score": 12500,
    "time_spent": 120,
    "difficulty": "medium"
])

getGlobalProperties

Singular.getGlobalProperties Method

Retrieves all currently set global properties. This method returns a dictionary containing all global properties that have been set for the SDK.

Signature

+ (NSDictionary *)getGlobalProperties;

Usage Example

Swift Objective-C
// Get all global properties
let properties = Singular.getGlobalProperties()
print("Global properties: \(properties)")

getLimitDataSharing

Singular.getLimitDataSharing Method

Retrieves the current data sharing limitation status. This method returns a boolean indicating whether data sharing is currently limited.

Signature

+ (BOOL)getLimitDataSharing;

Usage Example

Swift Objective-C
// Check if data sharing is limited
let isLimited = Singular.getLimitDataSharing()
if isLimited {
    print("Data sharing is currently limited")
}

handlePushNotification

Singular.handlePushNotification Method

Processes a push notification payload for attribution. This method should be called when your app receives a push notification to allow Singular to attribute it correctly.

Signature

+ (BOOL)handlePushNotification:(NSDictionary *)pushNotificationPayload;

Usage Example

Swift Objective-C
// Handle a received push notification
func userNotificationCenter(_ center: UNUserNotificationCenter, 
                            didReceive response: UNNotificationResponse, 
                            withCompletionHandler completionHandler: @escaping () -> Void) {
    let userInfo = response.notification.request.content.userInfo
    Singular.handlePushNotification(userInfo)
    completionHandler()
}

iapComplete

Singular.iapComplete Methods

Tracks in-app purchase completion events. These methods should be called when an in-app purchase transaction is completed.

Signatures

+ (void)iapComplete:(id)transaction;

+ (void)iapComplete:(id)transaction 
           withName:(NSString *)name;

+ (void)iapComplete:(id)transaction 
     withAttributes:(id)value, ...;

+ (void)iapComplete:(id)transaction 
           withName:(NSString *)name 
     withAttributes:(id)value, ...;

Usage Example

Swift Objective-C
// Track IAP completion
Singular.iapComplete(transaction)

// Track IAP completion with custom name
Singular.iapComplete(transaction, withName: "premium_upgrade")

isAllTrackingStopped

Singular.isAllTrackingStopped Method

Checks if all tracking is currently stopped. This method returns a boolean indicating whether tracking is currently stopped.

Signature

+ (BOOL)isAllTrackingStopped;

Usage Example

Swift Objective-C
// Check if tracking is stopped
if Singular.isAllTrackingStopped() {
    print("Tracking is currently stopped")
}

Returns whether the given link holder (typically an NSURL or NSUserActivity) represents a Singular Link. Use this to short-circuit your own deep-link handling when Singular will resolve the link via the SDK's singularLinksHandler.

+ (BOOL)isSingularLink:(id)linkHolder;
Swift Objective-C
// Inspect an incoming URL before handling it yourself
func application(_ app: UIApplication,
                 open url: URL,
                 options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
    if Singular.isSingularLink(url) {
        // Singular's singularLinksHandler will receive the resolved link.
        return true
    }

    // Fall through to your own deep-link handling
    return handleCustomURL(url)
}

limitDataSharing

Singular.limitDataSharing Method

Sets the data sharing limitation status. Use this method to limit data sharing based on user consent or privacy requirements.

Signature

+ (void)limitDataSharing:(BOOL)shouldLimitDataSharing;

Usage Example

Swift Objective-C
// To limit data sharing (e.g., when user opts out)
Singular.limitDataSharing(true)

// To enable full data sharing (e.g., when user opts in)
Singular.limitDataSharing(false)

registerDeviceTokenForUninstall

Singular.registerDeviceTokenForUninstall Method

Registers the device token for uninstall tracking. This method should be called with the push notification token to enable uninstall tracking.

Signature

+ (void)registerDeviceTokenForUninstall:(NSData *)deviceToken;

Usage Example

Swift Objective-C
// Register device token for uninstall tracking
func application(_ application: UIApplication, 
                 didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    Singular.registerDeviceTokenForUninstall(deviceToken)
}

resumeAllTracking

Singular.resumeAllTracking Method

Resumes all tracking activities that were previously stopped. Use this method to re-enable tracking after it has been stopped.

Signature

+ (void)resumeAllTracking;

Usage Example

Swift Objective-C
// Resume tracking when user opts back in
Singular.resumeAllTracking()

revenue

Singular.revenue Methods

Tracks revenue events with various parameters including currency, amount, and product details. This allows comprehensive revenue tracking for your application.

Signatures

+ (void)revenue:(id)transaction;

+ (void)revenue:(id)transaction withAttributes:(NSDictionary *)attributes;

+ (void)revenue:(NSString *)currency amount:(double)amount;

+ (void)revenue:(NSString *)currency 
         amount:(double)amount 
   withAttributes:(NSDictionary *)attributes;

+ (void)revenue:(NSString *)currency 
         amount:(double)amount 
     productSKU:(NSString *)productSKU 
    productName:(NSString *)productName 
productCategory:(NSString *)productCategory 
productQuantity:(int)productQuantity 
   productPrice:(double)productPrice;

Usage Example

Swift Objective-C
// Track revenue with currency and amount
Singular.revenue("USD", amount: 9.99)

// Track revenue with additional attributes
Singular.revenue("USD", amount: 19.98, withAttributes: [
    "product_id": "premium_gems",
    "quantity": 2
])

// Track revenue with detailed product information
Singular.revenue("USD",
                 amount: 19.98,
                 productSKU: "SKU123456",
                 productName: "Premium Sword",
                 productCategory: "Weapons",
                 productQuantity: 2,
                 productPrice: 9.99)

// Track revenue from a StoreKit SKPaymentTransaction
// (typically inside SKPaymentTransactionObserver.paymentQueue(_:updatedTransactions:))
func paymentQueue(_ queue: SKPaymentQueue,
                  updatedTransactions transactions: [SKPaymentTransaction]) {
    for transaction in transactions where transaction.transactionState == .purchased {
        Singular.revenue(transaction)
        SKPaymentQueue.default().finishTransaction(transaction)
    }
}

setCustomUserId

Singular.setCustomUserId Method

Sets a custom user ID for the current user. This allows you to associate Singular data with your own user identification system.

Signature

+ (void)setCustomUserId:(NSString *)customUserId;

Usage Example

Swift Objective-C
// Set custom user ID after user logs in
Singular.setCustomUserId("user_123456")

setDeviceCustomUserId

Deprecated feature: Use setCustomUserId instead.

Singular.setDeviceCustomUserId Method

Sets a custom user ID at the device level. This allows you to associate Singular data with your own user identification system at the device level.

Signature

+ (void)setDeviceCustomUserId:(NSString *)customUserId;

Usage Example

Swift Objective-C
// Set device-level custom user ID
Singular.setDeviceCustomUserId("device_user_123456")

setGlobalProperty

Singular.setGlobalProperty Method

Sets a global property that will be sent with all events. This allows you to add consistent attributes to all events without specifying them each time.

Signature

+ (BOOL)setGlobalProperty:(NSString *)key 
                 andValue:(NSString *)value 
         overrideExisting:(BOOL)overrideExisting;

Usage Example

Swift Objective-C
// Set a global property
let success = Singular.setGlobalProperty("user_tier", 
                                         andValue: "premium", 
                                         overrideExisting: true)
if success {
    print("Global property set successfully")
}

setLimitAdvertisingIdentifiers

Singular.setLimitAdvertisingIdentifiers Method

Enables or disables the runtime limit on advertising identifier collection. This is the runtime equivalent of the config-time property SingularConfig.limitAdvertisingIdentifiers and can be flipped at any point after Singular.start(_:).

This method is compiled out of the Singular Kids SDK build (guarded by #ifndef SINGULAR_KIDS). If you are integrating Singular-Kids-SDK, this method is unavailable — the Kids SDK enforces stricter identifier handling automatically.

Signature

+ (void)setLimitAdvertisingIdentifiers:(BOOL)enabled;

Usage Example

Swift Objective-C
// Limit advertising identifiers at runtime (e.g., after a consent dialog)
Singular.setLimitAdvertisingIdentifiers(true)

setLoggingEnabled

Singular.setLoggingEnabled Method

Toggles SDK logging at runtime. Runtime counterpart of SingularConfig.enableLogging. Logging is silent until both this is YES and setLogLevel: is set above SingularLogLevelNone.

Signature

+ (void)setLoggingEnabled:(BOOL)enabled;

Usage Example

Swift Objective-C
// Enable SDK logging for debug builds
#if DEBUG
Singular.setLoggingEnabled(true)
Singular.setLogLevel(.debug)
#endif

setLogLevel

Singular.setLogLevel Method

Sets the SDK log verbosity at runtime. Runtime counterpart of SingularConfig.logLevel. Available levels are defined in SingularLogLevel.h: SingularLogLevelNone, SingularLogLevelError, SingularLogLevelWarning, SingularLogLevelInfo, SingularLogLevelDebug, SingularLogLevelVerbose.

Signature

+ (void)setLogLevel:(SingularLogLevel)logLevel;

Usage Example

Swift Objective-C
// Set verbose logging for detailed debugging
Singular.setLoggingEnabled(true)
Singular.setLogLevel(.verbose)

setSessionTimeout

Singular.setSessionTimeout Method

Sets the session timeout in seconds. This determines how long a user session lasts after the app goes to the background.

Signature

+ (void)setSessionTimeout:(int)timeout;

Usage Example

Swift Objective-C
// Set session timeout to 2 minutes
Singular.setSessionTimeout(120)

skanGetConversionValue

Singular.skanGetConversionValue Method

Retrieves the current SKAdNetwork conversion value. This method returns the current conversion value used for SKAdNetwork attribution.

Signature

+ (NSNumber *)skanGetConversionValue;

Usage Example

Swift Objective-C
// Get the current SKAdNetwork conversion value
let conversionValue = Singular.skanGetConversionValue()
print("Current conversion value: \(conversionValue ?? 0)")

skanRegisterAppForAdNetworkAttribution

Singular.skanRegisterAppForAdNetworkAttribution Method

Registers the app for SKAdNetwork attribution. This method should be called to enable SKAdNetwork attribution on iOS.

Signature

+ (void)skanRegisterAppForAdNetworkAttribution;

Usage Example

Swift Objective-C
// Register for SKAdNetwork attribution
Singular.skanRegisterAppForAdNetworkAttribution()

skanUpdateConversionValue

Singular.skanUpdateConversionValue Methods

Updates the SKAdNetwork conversion value. These methods allow you to manually update the conversion value used for SKAdNetwork attribution.

Signatures

+ (BOOL)skanUpdateConversionValue:(NSInteger)conversionValue;

+ (void)skanUpdateConversionValue:(NSInteger)conversionValue 
                           coarse:(NSInteger)coarse 
                             lock:(BOOL)lock;

Usage Example

Swift Objective-C
// Update the SKAdNetwork conversion value
let success = Singular.skanUpdateConversionValue(5)
if success {
    print("Conversion value updated successfully")
}

// Update SKAdNetwork 4.0 conversion values (iOS 16.1+)
Singular.skanUpdateConversionValue(5,   // fine value (0-63)
                                   coarse: 1,   // coarse value (0=low, 1=medium, 2=high)
                                   lock: false)

start

Singular.start Method

Initializes the Singular SDK with the provided configuration. This is the first method you should call to start using the Singular SDK.

Signature

+ (BOOL)start:(SingularConfig *)config;

Usage Example

Swift Objective-C
// Create configuration object
let config = SingularConfig(apiKey: "SDK_KEY", andSecret: "SDK_SECRET")

// Configure additional options if needed
config.customUserId = "user-123456"
config.sessionTimeout = 60

// Initialize the SDK
Singular.start(config)

startSession

Singular.startSession Methods

Starts a new session with the Singular SDK. Multiple variants are available for different initialization scenarios including launch options, user activities, and deep link handling.

Signatures

+ (void)startSession:(NSString *)apiKey withKey:(NSString *)apiSecret;

+ (BOOL)startSession:(NSString *)apiKey 
             withKey:(NSString *)apiSecret 
    andLaunchOptions:(NSDictionary *)launchOptions 
withSingularLinkHandler:(void (^)(SingularLinkParams *))handler;

+ (BOOL)startSession:(NSString *)apiKey 
             withKey:(NSString *)apiSecret
    andLaunchOptions:(NSDictionary *)launchOptions 
withSingularLinkHandler:(void (^)(SingularLinkParams *))handler 
andShortLinkResolveTimeout:(long)timeoutSec;

+ (void)startSession:(NSString *)apiKey 
             withKey:(NSString *)apiSecret 
    andLaunchOptions:(NSDictionary *)launchOptions;

Usage Example

Swift Objective-C
// Simple session start
Singular.startSession("API_KEY", withKey: "API_SECRET")

// Session start with deep link handler
Singular.startSession("API_KEY", 
                      withKey: "API_SECRET", 
                      andLaunchOptions: launchOptions, 
                      withSingularLinkHandler: { params in
    if let deeplink = params.deeplink {
        print("Deep link received: \(deeplink)")
    }
})

stopAllTracking

Singular.stopAllTracking Method

Stops all tracking activities. Use this method to disable tracking when users opt out or for privacy compliance.

Signature

+ (void)stopAllTracking;

Usage Example

Swift Objective-C
// Stop tracking when user opts out
Singular.stopAllTracking()

trackingOptIn

Singular.trackingOptIn Method

Indicates that the user has opted in to tracking. Call this method when the user explicitly consents to tracking and data collection.

Signature

+ (void)trackingOptIn;

Usage Example

Swift Objective-C
// User has opted in to tracking
Singular.trackingOptIn()

trackingUnder13

Singular.trackingUnder13 Method

Indicates that the user is under 13 years old. Call this method to comply with COPPA and other regulations for users under 13 years old.

Signature

+ (void)trackingUnder13;

Usage Example

Swift Objective-C
// Notify Singular the user is under 13 years old
Singular.trackingUnder13()

unsetCustomUserId

Singular.unsetCustomUserId Method

Removes the previously set custom user ID. Call this method when the user logs out or when you no longer want to associate events with the current user ID.

Signature

+ (void)unsetCustomUserId;

Usage Example

Swift Objective-C
// Clear custom user ID when user logs out
Singular.unsetCustomUserId()

unsetGlobalProperty

Singular.unsetGlobalProperty Method

Removes a previously set global property. Call this method when you no longer want a specific global property to be sent with events.

Signature

+ (void)unsetGlobalProperty:(NSString *)key;

Usage Example

Swift Objective-C
// Remove a global property
Singular.unsetGlobalProperty("user_tier")