iOS Quick Start

Current iOS SDK Version 6.0.2

The TUNE SDK for the native iOS platform provides application session and event logging functionality. The Tune SDK for iOS is available in the form of a dynamic framework that you include in your iOS project; and support devices on iOS versions 8.0 and above.

Downloading the SDK

The effective size of Tune SDK for iOS is 1.9MB when the project iOS deployment target is 8.0 (oldest supported). This does not account for additional size caused by the Apple App Store encryption process. See App Store Considerations for more information.

  • Log into your TUNE account to add your app to the Attribution Analytics platform.
    • After it’s added to the TUNE platform, you can either Download and install the SDK yourself, or Install the TUNE CocoaPod.
  • The TUNE SDK is also available as an open-source framework with libraries for session and event measurement.

Installing the SDK

There are two methods available to install the TUNE iOS SDK.  You can either use Cocoapods or install manually with the instructions below.

Install Using Cocoapods

If you’re using CocoaPods, add pod 'Tune' inside the target..do..end block as follows:

target '<your_project_target>' do 
    pod 'Tune'
end
to your Podfile and run pod install.

Install Manually

Note: To manually install the TUNE iOS SDK, please follow these instructions.

Code Changes

In your AppDelegate file, import the Tune framework:

@import Tune;
and initialize it:

@interface AppDelegate () <TuneDelegate>
 
@end
 
@implementation AppDelegate 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Account Configuration info - must be set
    [Tune initializeWithTuneAdvertiserId:@"your_advertiser_ID"
                       tuneConversionKey:@"your_conversion_key"];
 
    // Register this class as a deeplink listener to handle deferred deeplinks and Tune Universal Links.
    // This class must conform to the TuneDelegate protocol, implementing the tuneDidReceiveDeeplink: and tuneDidFailDeeplinkWithError: callbacks.
    [Tune registerDeeplinkListener:self];
 
    // Uncomment this line to enable auto-measurement of successful in-app-purchase (IAP) transactions as "purchase" events
    //[Tune automateIapEventMeasurement:YES];
 
    return YES;
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Attribution will not function without the measureSession call included
    [Tune measureSession];
}

// Capturing Universal Links
- (BOOL)application:(UIApplication *)application continueUserActivity:(nonnull NSUserActivity *)userActivity restorationHandler:(nonnull void (^)(NSArray * _Nullable))restorationHandler {
    // Check if Tune will handle the Universal Link. If so, the deeplink will be handled in your tuneDidReceiveDeeplink: or tuneDidFailDeeplinkWithError: callback
    BOOL handledByTune = [Tune handleContinueUserActivity:userActivity restorationHandler:restorationHandler];
    
    // If handledByTune is false, handle the routing yourself
    if (!handledByTune) {
        ...
    }
    return YES;
}

// Capturing deeplinks for iOS >= 9.0
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString*, id> *)options {
    // When the app is opened due to a deep link, call the Tune deep link setter
    [Tune handleOpenURL:url options:options];
    // Take care of the routing yourself here
    ...
    return YES;
}

// Capturing deeplinks for iOS < 9.0
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    // When the app is opened due to a deep link, call the Tune deep link setter
    [Tune handleOpenURL:url sourceApplication:sourceApplication];
    // Take care of the routing yourself here
    ...
    return YES;
}

#pragma mark - TuneDelegate protocol implementation
// For more information, please see https://developers.tune.com/sdk/implementing-a-deferred-deep-link/#code-platform-ios 
- (void)tuneDidReceiveDeeplink:(NSString *)deeplink {
    NSLog(@"Tune deferred deeplink = %@", deeplink);
    
    // Handle opening deeplink
    ...
}

- (void)tuneDidFailDeeplinkWithError:(NSError *)error {
    NSLog(@"Tune failed to receive deferred deep link: error = %@", error);
}
@end

Note: The “your_advertiser_ID” and the “your_conversion_key” values correlate with the Advertiser ID and Conversion Key that TUNE provides when you create your Mobile App in TUNE. For information about the advertiser ID and conversion key, please visit Finding Advertiser ID and Conversion Key.

With the release of iOS 9, Apple introduced Universal Links to make the content in your apps discoverable. Essentially, Universal Links makes it easier to deep link  users from a web experience into your app experience. For instructions on how to configure your app and web browser to support Universal Links, please read Implementing iOS Universal Links.

Testing & Troubleshooting

  • To test the TUNE SDK implementation in your mobile app, you can do so straight from the TUNE platform itself rather than creating a test environment. Please visit Testing Your Mobile App.
  • There are features of the TuneDelegate protocol that can be useful to make sure events are being measured and transmitted correctly. Please visit Reading Server Responses.
  • If your app already has a pre-existing user base (people who have already installed your app), TUNE has several options to flag these users as Pre-Existing Users to prevent attributing these users to a marketing partner. For information about migrating existing users, please visit handle existing users prior to SDK implementation.
  • When you submit an app to the Apple App Store you may be asked whether your app includes cryptography. The Tune iOS SDK uses Apple's CommonCrypto library to AES encode data that is sent to the server (with 256 bit keys). We also use HTTPS. Please refer to our open source repository if you would like to review the details of how we are handling encryption: https://github.com/TuneOSS/sdk-release/tree/master/sdk-ios/Tune

Measuring Events

After you implement the TUNE SDK in your mobile app and start logging sessions, you can move on to logging a wide variety of in-app events such as registrations and in-app purchases.

The Tune SDK natively supports measurement of the following In-App events.

Or to build your own custom event, please visit our Event Builder article.

No Comments

Leave a reply