SDK Installation
  • 07 May 2024
  • 3 Minutes to read

    SDK Installation


      Article Summary

      Suggested reading: Basic SDK Setup

      This guide helps you understand the requirements for SDK setup, installations, and how to initialize it.

      Required For Setup

      • An installed Mac with Xcode 
      • An iOS device. The Xcode simulator does not support push notifications so you must test on a real device.
      • An Apple Push Services Certificate for iOS
      • An Android device or emulator with a minimum API 16
      • A Huawei Messaging Service Server Key and agconnect-services.json imported into your app (for only Huawei Devices without Google Service)
      • A Firebase Cloud Messaging Server Key and google-services.json imported into your app
      • Android Studio
      • To use Cordova, you need to install Node.js on your computer. For details about the requirements of Cordova, refer to Installing the Cordova CLI.
      • To use Cordova, you need to install Node.js on your computer.
      Your title goes here
      Your project's Cordova version should be higher than 11.0.0.

      Required Installation

      1. Install Cordova CLI if you haven't installed it before.
      npm install -g cordova

      2. Create a Cordova project or use your existing one. To create a Cordova project, you can use the cordova create path [id [name [config]]] [options] command. For more details, refer to Cordova create command.
      cordova create sampleApp com.company.sampleapp SampleApp

      3. Add the Android, iOS, or both platforms to the project if you haven't added them before.
      cordova platform add android
      cordova platform add iOS

      Integrating Plugin to Cordova Project

      1. Update the widget ID property that is specified in the config.xml file. It must be the same with the client > package_name value of the agconnect-services.json file for Huawei configuration.
      2. Copy the google-services.json and agconnect-services.json files to the project’s root directory.
      3. Install the Insider Cordova plugin.
      cordova plugin add cordova-plugin-insider
      4. Add the keystore(.jks) and build.json files to the <project_root>/platforms/android/app directory.

      Your title goes here
      This step is required for Huawei configuration.

      5. Open the Pod file in the <project_root>/platforms/ios/ directory and configure the Pod file that the Insider SDK depends on.

      # DO NOT MODIFY -- auto-generated by Apache Cordova
      source 'https://cdn.cocoapods.org/'
      platform :ios, '11.0'
      use_frameworks!
      target 'InsiderDemo' do
      	project 'InsiderDemo.xcodeproj'
      	pod 'InsiderMobile'
      	pod 'InsiderHybrid'
      end
      
      target 'InsiderNotificationContent' do
          inherit! :search_paths
          # Pods for InsiderNotificationContent
          pod "InsiderMobileAdvancedNotification"
      end
      target 'InsiderNotificationService' do
          inherit! :search_paths
          # Pods for InsiderNotificationService
          pod "InsiderMobileAdvancedNotification"
      end

      6. Configure partner name in the <project_root>/android/cordova-plugin-insider/sampleApp-build-extras.gradle.

      // DO NOT FORGET to change partner_name.
      // Use only lowercase and partner_name is provided by Insider.
      
      manifestPlaceholders = [ partner: "partner_name" ]
      

      7. Open the build.gradle file in the <project_root>/android/app directory. Add signingConfigs entry to Android property according to your keystore information. Enable signingConfig configuration in debug and release the release and debug attributes in buildTypes. Apply com.huawei.agconnect plugin.

      ...
      
      android {
          ...
      
          // Add signingConfigs according to your keystore information
           signingConfigs {
              release {
                  storeFile file(xxx.jks')
                  keyAlias 'xxx'
                  keyPassword 'xxx'
                  storePassword 'xxx'
                  v1SigningEnabled true
                  v2SigningEnabled true
              }
          }
      
          buildTypes {
              release {
                  signingConfig signingConfigs.release
                  minifyEnabled true
                  shrinkResources true
                  proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
              }
              debug {
                  signingConfig signingConfigs.release
                  minifyEnabled false
                  proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
              }
          }
      ...
      
      apply plugin: 'com.huawei.agconnect' // Apply com.huawei.agconnect plugin. This line must be added to the end of the file.

      8. Build your project.
      cordova build
      9. Run the app.
      cordova run android --device
      cordova run iOS --device

      Initialize SDK

      1. Add the following to the bottom of the first Javascript file that loads with your app. This is <project-dir>/www/js/index.js for most Cordova projects.

      var app = {
          initialize: function () {
              document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
          },
      
          onDeviceReady: function () {
              initSDK();
          }
      };
      
      async function initSDK() {
          //Update the PARTNER_NAME and APP_GROUP_ID value below with yours.
          await window.Insider.init('PARTNER_NAME', 'APP_GROUP_ID',
              (callback) => {
                  switch ((callback.result || {}).type) {
                      case window.Insider.callbackType.NOTIFICATION_OPEN:
                          console.log('[INSIDER][NOTIFICATION_OPEN]: ', callback.result || {});
                          break;
                      case window.Insider.callbackType.INAPP_BUTTON_CLICK:
                          console.log('[INSIDER][INAPP_BUTTON_CLICK]: ', callback.result || {});
                          break;
                      case window.Insider.callbackType.TEMP_STORE_PURCHASE:
                          console.log('[INSIDER][TEMP_STORE_PURCHASE]: ', callback.result || {});
                          break;
                      case window.Insider.callbackType.TEMP_STORE_ADDED_TO_CART:
                          console.log('[INSIDER][TEMP_STORE_ADDED_TO_CART]: ', callback.result || {});
                          break;
                      case window.Insider.callbackType.TEMP_STORE_CUSTOM_ACTION:
                          console.log('[INSIDER][TEMP_STORE_CUSTOM_ACTION]: ', callback.result || {});
                          break;
                      case window.Insider.callbackType.INAPP_SEEN:
                          console.log('[INSIDER][INAPP_SEEN]: ', callback.result || {});
                          break;
                  }
              })
      };
      
      app.initialize();

      2. Complete the Android and iOS native steps.

      Once you complete the SDK installation, you can proceed with setting callbacks.


      Was this article helpful?


      What's Next
      ESC

      Eddy, a super-smart generative AI, opening up ways to have tailored queries and responses