Docs

Last modified: Friday, 15 January 2021

SDK Integration for iOS

  1. Drag and Drop the Framework in your Project Folder iOS Implementation of the Sharify Media SDK
  2. Check Frameworks, Libraries and Embedded Content under the “General” tab. The imported Framework should appear there. Then select “Embed & Sign” iOS Implementation of the Sharify Media SDK
  3. Import the Framework
    • For Swift:
    • Import The Framework using the import TrackDownloadManager statement in the file where you want to use the Framework's methods. We are importing in AppDelegate.swift iOS Implementation of the Sharify Media SDK
    • For Objective C:
    • Import The Framework using the #import <TrackDownloadManager/TrackDownloadManager-Swift.h> statement in the “.m file” where you want to use the Framework's methods. We are importing in AppDelegate.m iOS Implementation of the Sharify Media SDK
  4. Set “Enable Bitcode” to “No” in the Build Settings iOS Implementation of the Sharify Media SDK
  5. Use the logDownload method of the Framework to log the download
    • For Swift:
          
      private func trackAppDownload(){
          DownloadTracker.sharedManager.logDownload {(success, error) in
              var message = ""
              if error != nill{
                  message = error!.localizedDescription
              } else {
                  message = (success as? String) ?? ""
              }
              NSLog("%@", message)
              DispatchQueue.main.async {
                  let alert = UIAlertController.init(title: "Download Tracker", message: message, preferredStyle: .alert)
                  alert.addAction(UIAlertAction.init(title: "OK", style: .default, handler: {(action) in }))
                  self.window?.rootViewController?.show(alert, sender: self)
              }
          }
      }
                                      
      iOS Implementation of the Sharify Media SDK
    • For Objective C:
          
      - (void)logDownload{
          [[DownloadTracker sharedManager] logDownloadWithCompletionHandler:^(id response, NSError * error) {
              NSString *message = @"";
              
              if (error != nil) {
                  message = error.localizedDescription;
              }else{
                  message = response;
              }
              dispatch_async(dispatch_get_main_queue(), ^{
                  NSLog(@"%@", message);
                  
                  UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"YourCampaign" message:message preferredStyle:UIAlertControllerStyleAlert];
                      
                  UIAlertAction * okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action){
                      }];
                      [alert addAction:okAction];
                      [[[self window] rootViewController] showViewController:alert sender:self];
              });
              
          }];
      }
                                          
      iOS Implementation of the Sharify Media SDK

SDK Integration for Android


Java prerequisites:

  • If your Java project doesn't already have Kotlin support, click on Tools > Kotlin > Configure Project in Kotlin. Choose Configurator Java with Gradle, select “All modules”or “All modules with kotlin files” and click ok. Android Implementation of the Sharify Media SDK
  • Make sure your project level build.gradle looks like this:
        
    // Project build.gradle file.
    buildscript {
        ext.kotlin_version ='1.4.10'
        ...
        dependencies {
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        }
    }
                                
    Android Implementation of the Sharify Media SDK
  • Make sure your app level build.gradle also has Kotlin in plugins and as a dependency:
        
    // Inside each module using kotlin
    plugins{
        id'kotlin-android'
    }
    dependencies{
        implementation"org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    }
                                
    Android Implementation of the Sharify Media SDK


  1. Click on File > New > Import Module in Android Studio Android Implementation of the Sharify Media SDK
  2. Select the project from the directory and click on Finish Android Implementation of the Sharify Media SDK
  3. Go to your “settings.gradle” file and check if the appDataTracker module is included Android Implementation of the Sharify Media SDK
  4. Go to your “build.gradle” (app level) file and the imported module should be shown there. If the module is not automatically imported paste these in:
        
    implementation project(':appDataTracker')
                                
    Android Implementation of the Sharify Media SDK
  5. In your app level “build.gradle” file, make sure your projects minSdkVersion is 17. Alternatively you can change the module’s “build.gradle(appDataTracker)” version to according your app’s minSdkVersion. Android Implementation of the Sharify Media SDK
  6. Import the AppTracker in your MainActivity and add the method startTrack to track the download
    (To test if the tracker is working you can show a toast or dialog in the onDataTracked method. Don't forget to remove this for production.)
    • For Kotlin:
          
      import com.appdatatracker.utils.showAlertDialog
      import com.appdatatracker.views.AppTracker
      
      class MainActivity : AppCompatActivity(), AppTracker.onTrackListener {
          override fun onCreate(savedInstanceState: Bundle?) {
              super.onCreate(savedInstanceState)
              setContentView(R.layout.activity_main)
              trackData()
          }
          private fun trackData(){
              intent?.action?.let{
                  if (it == Intent.ACTION_VIEW){
                      startTrack()
                  }
              }
              startTrack()
          }
          private fun startTrack(){
              AppTracker(this).startTrack(
                      BuildConfig.APPLICATION_ID,
                      BuildConfig.VERSION_NAME,
                      "Your Android Project",
                      this
              )
          }
      
          override fun onDataTracked(message: String) {
              showAlertDialog(message, negativeBtnText = "")
          }
      }
                                          
      Android Implementation of the Sharify Media SDK
    • For Java:
          
      import com.appdatatracker.views.AppTracker;
      
      public class MainActivity extends AppCompatActivity implements AppTracker.onTrackListener {
      
          @Override
          protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_main);
              startTrack();
          }
      
          private void startTrack() {
              new AppTracker(this).startTrack(
                      BuildConfig.APPLICATION_ID,
                      BuildConfig.VERSION_NAME,
                      getString(R.string.app_name),
                      this
              );
          }
      
          @Override public void onDataTracked(
                  @NotNull String message
          ) {
          // show toast or dialog
          }
      }
                                          
      Android Implementation of the Sharify Media SDK