iOS SDK integration for developers

  • Advertisers
  • Developers

ios.pngSDK Version: 4.11.0 (Release notes)

1. Overview

AppsFlyer's SDK provides app installation and event recording functionality. We have developed an SDK that is highly robust, secure, lightweight and very simple to embed.

You can record installs, updates, and sessions and also record additional in-app events beyond app installs (including in-app purchases, game levels, etc.) to evaluate ROI and user engagement levels.

1.1 SDK integration - what you need to do

Tab Purpose Result

SDK Integration (Mandatory)

Shows how to add and configure the SDK.
  • A new organic install in your app's dashboard.
  • A new non-organic install in your app's dashboard.

Core APIs (Highly Recommended)

Shows how to use the SDK core APIs. These APIs allow you to measure in-app events and revenue, perform deep linking and gather conversion data.

In-app events and revenue appear on your dashboard.

You are able to perform deep linking.

Additional APIs

Shows how to implement and use optional APIs such as uninstall measurement, Referrals (user invite attribution), and push notifications.

You are able to measure uninstalls, referrals, user engagements with push notifications, handle user privacy scenarios and more.

API reference

Quick reference of the SDK APIs for developers

 

1.2 SDK Compatibility with iOS

  • The iOS SDK is compatible with all iOS devices (iPhone, iPod, iPad) with iOS version 6 and later.
  • The iOS SDK is fully compliant with Apple's IPv6 DNS64/NAT64 networks. For more information, see here.

This tab explains how to implement and initialize the AppsFlyer SDK, and is written for app developers. After completing this tab, you will see two installs in your app's dashboard, one organic and one non-organic.

2. Adding the SDK to your app

2.1 Downloading and adding the SDK to Xcode

CocoaPodsCarthageStatic FrameworkStatic Lib
  1. Download and install the latest version of CocoaPods.
  2. Add the following row to your Podfile:
    pod 'AppsFlyerFramework'
  3. Run pod install.
  4. Make sure you use the .xcworkspace file to open your project in Xcode, instead of the .xcodeproj file, from here on out.

2.2 Adding ad support frameworks

AppsFlyer's SDK uses the following native frameworks:

AdSupport.framework
This framework is required to collect the IDFA from devices.
Without IDFA you cannot attribute installs to Facebook Ads, Twitter, Google ads and other networks.
iAd.framework
This framework is required to record and measure the performance of Apple Search Ads in your app.

To add ad support frameworks:

  1. In your Xcode project, select your project's target.
  2. Select the General tab for your target.
  3. Expand the Linked Frameworks and Libraries section.
  4. Click + to add a framework.
  5. Search for AdSupport.framework
  6. Select AdSupport.framework from the list.

Repeat the process for iAd.framework.

3. Implementing and initializing the SDK

This section describes how to implement and initialize AppsFlyer iOS SDK.

3.1 Retrieving your dev key

AppsFlyer uses the dev key to uniquely identify your account. The dev key is mandatory because it allows the SDK to securely send and retrieve data that belongs to your AppsFlyer account.

To do:

  1. Go to your app's dashboard.
  2. In the dashboard, under Configuration click App Settings.
  3. Copy your dev key.

3.2 Configuring the SDK in app delegate

Objective-CSwift
  1. In AppDelegate.h, do the following:
    • Import AppsFlyerLib/AppsFlyerTracker.h.
    • Add AppsFlyerTrackerDelegate to the interface declaration.
    #import <AppsFlyerLib/AppsFlyerTracker.h>
    @interface AppDelegate : UIResponder <UIApplicationDelegate, AppsFlyerTrackerDelegate>
  2. In AppDelegate.h, add the following: AppsFlyerLib/AppsFlyerTracker.h: #import <AppsFlyerLib/AppsFlyerTracker.h>

3.3 Initializing the SDK

  1. Initialize the SDK in the didFinishLaunchingWithOptions method with your app ID taken from iTunes Connect and your AppsFlyer dev key. Also, add the API methods to handle conversion data and deep linking.
    Objective-CSwift
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        /** APPSFLYER INIT **/
        [AppsFlyerTracker sharedTracker].appsFlyerDevKey = @"<DEV_KEY>";
        [AppsFlyerTracker sharedTracker].appleAppID = @"<APP_ID>";
        
        [AppsFlyerTracker sharedTracker].delegate = self;
        
        /* Set isDebug to true to see AppsFlyer debug logs */
        [AppsFlyerTracker sharedTracker].isDebug = true;
    
        return YES;
    }
    
    // rest of your code, methods such as applicationWillResignActive, applicationDidEnterBackground etc.
    
    //get conversion data and deep linking
    
    -(void)onConversionDataReceived:(NSDictionary*) installData {
      //Handle Conversion Data (Deferred Deep Link)
      
    }
    
    -(void)onConversionDataRequestFailure:(NSError *) error {
      
      NSLog(@"%@",error);
    }
    
    
    - (void) onAppOpenAttribution:(NSDictionary*) attributionData {
      
      //Handle Deep Link
    }
    
    - (void) onAppOpenAttributionFailure:(NSError *)error {
      NSLog(@"%@",error);
    }
    
    // Reports app open from a Universal Link for iOS 9 or above
    - (BOOL) application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray<id> *restorableObjects))restorationHandler {
        [[AppsFlyerTracker sharedTracker] continueUserActivity:userActivity restorationHandler:restorationHandler];
        return YES;
      }
    
      // Reports app open from deep link from apps which do not support Universal Links (Twitter) and for iOS8 and below
      - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString*)sourceApplication annotation:(id)annotation {
        [[AppsFlyerTracker sharedTracker] handleOpenURL:url sourceApplication:sourceApplication withAnnotation:annotation];
        return YES;
      }
      // Reports app open from deep link for iOS 10
      - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
      options:(NSDictionary *) options {
        [[AppsFlyerTracker sharedTracker] handleOpenUrl:url options:options];
        return YES;
      }
    

  2. Add the following code at the applicationDidBecomeActive function:

    Objective-CSwift
    - (void)applicationDidBecomeActive:(UIApplication *)application { 
    // attribute Installs, updates & sessions(app opens) 
    // (You must include this API to enable SDK functions) 
    [[AppsFlyerTracker sharedTracker] trackAppLaunch]; 
    // your other code here.... }

4. Testing installs

Now you are ready to test the SDK integration by simulating organic and non-organic installs.

4.1 Whitelisting your test device

Before you start testing installs, whitelist the device you are going to test on.

4.2 Simulating an organic install

Organic installs are unattributed installs which are usually direct installs from app stores.

To simulate an organic install:

  1. Make sure you have a mobile device connected to your computer.
  2. In Xcode, open the debug terminal.
  3. From Xcode Studio, install the app on the device or simulator.
  4. Wait for the app to launch.
  5. In the debug terminal, look for your app's package name.

You should see the following:

xcode_debug_terminal_organic.png

Send Track-App-Launch in the log indicates that the SDK reports an install. This data comes from the onConversionDataReceived method in app delegate. Getting conversion data is discussed later in this guide.

An organic install should now appear on the Overview page of the application's dashboard.

If you don't see an install in the app's dashboard, see our SDK troubleshooting guide.

4.3 Simulating a non-organic install

A non-organic install is an attributed install that usually follows an ad engagement. You can simulate a non-organic install by using attribution links.

To do:

  1. Find out what is the itunes ID name of your app e.g. id123456789.
  2. In the URL below, replace <APP_ID> with your app's itunes ID:
    https://app.appsflyer.com/<APP_ID>?pid=sdk_test&c=sdk_test
    The pid parameter represents the media source name. The c parameter represents the campaign name.
  3. Send this URL to the device (e.g. via email or WhatsApp).
  4. On the device, click on the URL.
    • If the app is listed in the app store, you are redirected to the app store. Don't download the app from the app store. Proceed to step 5.
    • If the app is not listed in the app store and is still in development, the screen shows a message that the app is not available in the app store. Simply proceed to step 5.
  5. In Xcode Studio, open the debug terminal.
  6. Connect the device to your computer using a USB cable.
  7. From Xcode, Install the app on the device.
  8. In the debug terminal, look for your app's itunes ID.

You should see the following:

xcode_debug_terminal.png

A non-organic install should now appear in the Overview page of the application's dashboard.

Was this article helpful?
10 out of 18 found this helpful

Comments

1 comment
  • Hi everyone!

    We want to update you that a new AppsFlyer iOS SDK has been released - version 4.10.3.

    This version supports iOS 13 updates, specifically push token retrieval for Uninstall Measurement.
    The new version also includes bugs fixes and improvements.

    We recommend that you update your app to use version 4.10.3.

    Thank you!

    0
    Comment actions Permalink

Please sign in to leave a comment.