1. Home
  2. Integrations
  3. iOS Native Integration

iOS Native Integration

Install the SDK

Download the latest iOS Native SDK

Note: Please refer to the iOS SDK Change log for details about the changes/upgrades on the latest SDK version from previous versions.

The mTracktion SDK should contain the following files:

  1. mTraction.framework: This is the SDK library that has to be integrated in the application.
  2. mTracktionResources.bundle: This is the SDK library that has to be integrated in the application.

The step-by-step integration process has been described in detail in the coming sections.

  1. Basic Integration Settings
  2. Installs Tracking
  3. App Session Tracking (Optional)
  4. In App Events Integration (Optional)
  5. Application Push Notifications(Optional)

1. Basic Integration Settings

  1. Go to your Project’s Build Phases. Follow the screenshot.
  1. Click on the “+” under “Link Binary With Libraries” to add a new library. Then click on the “Add Other” button. Follow the Screenshot
  2. Click on Add “Other Tab” and browse mTraction.framework and include in the project.
  3. Add the supporting native frameworks in the above-described manner. These frameworks can be found in the native frameworks list already. (Developer need not click on Add Other button.)
    • AdSupport.framework
    • CoreTelephony.framework
    • CoreData.framework
    • UIKit.framework
    • Foundation.framework
  4. To add the mTractionResources.bundle file, simply drag mTractionResources.bundle file into your Xcode, Classes folder. Follow the screenshot.
  5. Also To add an exception to their Info.plist to allow affle http connection for iOS 9.0 and above:

2. Installs Tracking

Follow the below steps to track download conversions:

  1. Open your project info.plist available under the Supporting Files section in the Project File Navigator on Xcode.Example: If your project name is mTractiontrackertest, then the plist file name shall be, mTractiontrackertest-Info.plist.
  2. Add a new key in the Information Property List section of the selected project info.plist.

    Key = appToken
    Value Type = String
    Value = <App_Token>

     

    Note: The App_Token is provided to you as a part of the Application Registration process on the mTraction Platform.

 

3. App Session Tracking (Optional)

Note: App Session implementation is optional for your Application. However, for Active Sessions and Session duration related data – this needs to be configured in your Application. Also note that this can generate a lot of traffic and hence cost if the request is large.

To track App Session call the below callbacks in predefined methods in AppDelegate file.

-(void)applicationWillResignActive:(UIApplication *)application
{  
 [[MTraction mTractionManager]applicationWillResignActive];
}

-(void)applicationDidBecomeActive:(UIApplication *)application
{
 [[MTraction mTractionManager]applicationDidBecomeActive];
}

4. In App Events Integration (Optional)

 

  • At this stage, you might be interested in implementing certain In App events that needs to be tracked in order to measure your Application’s User Engagement after being installed. We have provided a list of generic events that you may need to implement depending on its necessity to your Application. Please follow the documentation (with examples) to implement them on your Application: Generic In App Events Setup
  • Additionally, we have also provided sets of predefined In App events along with their respective keys setup (with example usage) based on the Industry or Vertical your Application is associated with. Please refer to the link to the various Vertical based Events integration guides: Vertical Specific Events Setup Guides
  • Additionally, you can implement custom events to track specific behavior on your application. Please follow the documentation (with example): Custom Events Setup Guide

5. Application Push Notifications(Optional)

Follow the below steps to track download conversions:

  1. Open your project info.plist available under the Supporting Files section in the Project File Navigator on Xcode.Example: If your project name is mTractiontrackertest, then the plist file name shall be, mTractiontrackertest-Info.plist.
  2. Add a new key in the Information Property List section of the selected project info.plist info.plist.

    Key = mt_PushNotification
    Value Type = Boolean
    Value = YES

     

  3. Configure Push Notification-We need to make a few modification to the app delegate in order to receive push notifications. Include the MTraction.h header file in App delegate To register the current device for push, call the method [application registerForRemoteNotificationTypes:] in the app delegate’s [application:didFinishLaunchingWithOptions:] method.
  4. – (BOOL)application:(UIApplication *)application
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Register for push notifications
    [self registerUserDeviceForRemoteNotifications];
    return YES;
    }
    
    
    - (void)registerUserDeviceForRemoteNotifications{
        
        
      if([[MTraction mTractionManager] getEnablePushNotification]){
        if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0){
          [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
          [[UIApplication sharedApplication] registerForRemoteNotifications];
        }
        else{
          [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
           (UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)];
        }
      }
    }
  5. Setting up the Device Registration-If the registration is successful, the callback method [application:didRegisterForRemoteNotificationsWithDeviceToken:] in the application delegate will be executed. We will need to implement this method and use it to inform mTraction platform about this new device.
  6. - (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
    {
      // send device token on mTraction platform
      [[MTraction mTractionManager] setDeviceToken:deviceToken];
    }
    
    
    
  7. Setting up the Push Notification HandlersApplication State : In-Active/Background When a push notification is received while the application is not in the foreground, it is displayed in the iOS Notification Center. When We click on push massage open app and handle by [application:didFinishLaunchingWithOptions:method.  
  8. – (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
    //Remove push msg and badge from Notification center and app
    [[UIApplication sharedApplication] setApplicationIconBadgeNumber:1];
    [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
    //Send Push open msg to mTraction Platform
      [[MTraction mTractionManager] inAppPushNotification:userInfo];
    
    
    }

    Application State : Active/Foreground
     
    If the notification is received while the app is active, it is up to the app to handle it. To do so, we can implement the [application:didReceiveRemoteNotification] method in the app delegate. Also developer can set custom/own message box in this method.

    (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
    //Remove push msg and badge from Notification center and app
    [[UIApplication sharedApplication] setApplicationIconBadgeNumber:1];
    [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
    //Send Push open msg to mTraction Platform
      [[MTraction mTractionManager] inAppPushNotification:userInfo];
    // Customize your push notification Alert………….
    }
  9. Push Notification On/Off Setting from App(Optional)
    • Push Notification On Setting:
      Add below line of code in your On UISwitch/UIButton Event Action/Method.
  10. [[MTraction mTractionManager] setEnablePushNotification:YES];
    
    
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0){
    //For iOS 8.0 and above
    [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
    [[UIApplication sharedApplication] registerForRemoteNotifications];
    }else{
    //For less iOS than 8.0
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
    (UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)];
    }
    • Push Notification Off Setting:
      Add below line of code in your Off UISwitch/UIButton Event Action/Method.
  11. [[MTraction mTractionManager] setEnablePushNotification:NO];
      [[UIApplication sharedApplication] unregisterForRemoteNotifications];

Articles

Was this article helpful to you? Yes No

How can we help?