Cordova Plugin

Version:- 1.1.24

Step 1: Depend on it

Run the following line of code in your project root terminal to install the plugin.

cordova plugin add [email protected]

Android Native Setup

Step 1: Enable multidex in androidX if required

To enable do the following in your app build.gradle

android {
defaultConfig {
        multiDexEnabled true
    }
}

dependencies {
    implementation 'androidx.multidex:multidex:2.0.1'
}

In AndroidManifest.xml

<application  
name="androidx.multidex.MultiDexApplication">

OR If you have your own Application class called MyApplication then do the following

MyApplication extends MultiDexApplication

Step 2: Add following lines of code in gradle.properties

android.enableJetifier=true
android.useAndroidX=true

Here ends adding dependency related to android native, sync and build your app before further integration.

iOS Native Setup

Step 1: Install pod

Run the following line of code in your project root terminal to install the plugin.

pod install

Step 2: CDVAppDelegate.h

In your project structure navigate as follows to open CDVAppDelegate.h file

Your Project -> platforms/ios -> CordovaLib -> Classes -> Public

Open this file and add following lines of code

#import <Foundation/Foundation.h>
#import "CDVViewController.h"
 
@interface CDVAppDelegate : NSObject <UIApplicationDelegate>{}
 
 
 
//Lines to be added starts here
@property (nonatomic, strong) IBOutlet UIWindow* window;
@property (nonatomic, strong) IBOutlet CDVViewController* viewController;
@property (strong, nonatomic) UINavigationController *navController;
//Lines to be added ends here
 
@end

Step 2: CDVAppDelegate.m

In your project structure navigate as follows to open CDVAppDelegate.m file

Your Project -> platforms/ios -> CordovaLib -> Classes -> Public

Open this file and add following lines of code inside didFinishLaunchingWithOptions method

/**
* This is main kick off after the app inits, the views and Settings are setup here. (preferred - iOS4 and up)
*/
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
   CGRect screenBounds = [[UIScreen mainScreen] bounds];
 
   self.window = [[UIWindow alloc] initWithFrame:screenBounds];
   self.window.autoresizesSubviews = YES;
 
   // only set if not already set in subclass
   if (self.viewController == nil) {
       self.viewController = [[CDVViewController alloc] init];
   }
  
 
 
//lines to be added starts here
   self.navController = [[UINavigationController alloc] initWithRootViewController:self.viewController];


   self.window.rootViewController = self.navController;
//lines to be added ends here
 
   [self.window makeKeyAndVisible];
 
   return YES;
}

Here ends adding dependency related to cordova plugin, clean and build your app before further integration.

Cordova Setup

Get Partner Id

You can find the partner ID in Flyy Dashboard.
Go to Settings -> SDK Keys

Register Package Name

You can register the package name in Flyy Dashboard.
Go to Settings -> Connect SDK

Set Package Name

You can set your package name using this method. Kindly make sure the package name should be the same as your package name given while connecting the SDK in the dashboard.

cordova.plugins.FlyyPlugin.setAppPackage("<package_name>", function (data) {
        console.log("Set Package Name: " + data)
    }, function (data) {
        console.log("Set Package Name Error: "+data)
    });

SDK Initialization

Initialize sdk in your application or main entry point of the app.

cordova.plugins.FlyyPlugin.initSdk("<partner_id>", "stage/production", function (data) {
        console.log("Init SDK Success: " + data)
    }, function (data) {
        console.log("Init SDK Error : " + data)
    });

For Referral
cordova.plugins.FlyyPlugin.initWithReferrerReceivedCallback("<partner_id>", "stage",function (data) {
          // alert("Hello: "+data)
       }, function (data) {
          // alert("ErrorOpen: "+data)
       });

Set Theme Colors

Please note this is a mandatory step to set theme colors and should be done immediately after initialization of Flyy SDK.

//Parameters to be passed are colorPrimary and colorPrimaryDark
cordova.plugins.FlyyPlugin.setThemeColor("#ffa500", "#ffa500", function (data) {
        console.log("Set theme color Success : " + data)
    }, function(data) {
        console.log("Set theme color Error : " + data)
    });

Set unique User ID with and without Segment ID

To complete the initialization process, you must call either setNewUser() or setUser().

  • setNewUser() should be called only if it’s a new user.
  • setUser() should be called if the user is an existing user. Call setUser() every time the app opens to make the sdk work.
//FOR SET USER

//set user id
cordova.plugins.FlyyPlugin.setUser("<user_id>", "<segment_id>", function (data) {
        console.log("Set User Success : " + data)
    }, function (data) {
        console.log("Set User Error : " + data)
    });



//For SET NEW USER

//set new user id
cordova.plugins.FlyyPlugin.setNewUser("<user_id>", function (data) {
        console.log("Set New User Success : " + data)
    }, function (data) {
        console.log("Set New User Error : " + data)
    });

Set Name

This will be shown in the screens wherever username is displayed

cordova.plugins.FlyyPlugin.setUsername("<user_name>", function (data) {
        console.log("Set User Name Success : " + data)
    }, function (data) {
        console.log("Set User Name Error : " + data)
    });

Offers Screen

To open offers screen for user

cordova.plugins.FlyyPlugin.startOfferActivity("<segment_id>", function (data) {
        console.log("Offers Page Success : " + data)
    }, function (data) {
        console.log("Offers Page Error : " + data)
    });

Rewards Screen

To open rewards screen for user

cordova.plugins.FlyyPlugin.startRewardsActivity("<segment_id>", function (data) {
        console.log("Rewards Page Success : " + data)
    }, function (data) {
        console.log("Rewards Page Error : " + data)
    });

Wallet Screen

To open wallet screen for user

cordova.plugins.FlyyPlugin.startWalletActivity("<segment_id>", function (data) {
        console.log("Wallet Page Success : " + data)
    }, function (data) {
        console.log("Wallet Page Error : " + data)
    });

Handle notifications for android

If notification_source is flyy_sdk in the notification payload then call the following line of code to let us handle flyy notifications

cordova.plugins.FlyyPlugin.handleNotification("remote_data", function (data) {
        console.log("Handle notification Success : " + data)
    }, function(data) {
        console.log("Hanle notification Error : " + data)
    });

Send FCM token to server only for iOS

cordova.plugins.FlyyPlugin.handleForeGroundNotification("<userdata>", function (data) {
        console.log("Handle notification Success : " + data)
    }, function(data) {
        console.log("Hanle notification Error : " + data)
    });

Handle foreground notifications for ios

If notification_source is flyy_sdk in the notification payload then call the following line of code to let us handle flyy notifications

cordova.plugins.FlyyPlugin.handleForeGroundNotification("<userdata>", function (data) {
        console.log("Handle notification Success : " + data)
    }, function(data) {
        console.log("Hanle notification Error : " + data)
    });

Handle background notifications for ios

If notification_source is flyy_sdk in the notification payload then call the following line of code to let us handle flyy notifications

cordova.plugins.FlyyPlugin.handleBackGroundNotification("<userdata>", function (data) {
        console.log("Handle notification Success : " + data)
    }, function(data) {
        console.log("Hanle notification Error : " + data)
    });

Release FAQ’s

Proguard Rules

If you are using proguard, please add these following rules to your proguard-rules.pro before you release the app.

#Retrofit does reflection on generic parameters. InnerClasses is required to use Signatureand
# EnclosingMethod is required to use InnerClasses.
-keepattributes Signature, InnerClasses, EnclosingMethod
# Retrofit does reflection on method and parameter annotations.
-keepattributes RuntimeVisibleAnnotations, RuntimeVisibleParameterAnnotations
#Retain service method parameters when optimizing.
-keepclassmembers,allowshrinking,allowobfuscation interface * { @retrofit2.http.* <methods>;}
# Ignore annotation used for build tooling.
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
# Ignore JSR 305 annotations for embedding nullability information.
-dontwarn javax.annotation.**
# Guarded by a NoClassDefFoundError try/catch and only used when on the classpath.
-dontwarn kotlin.Unit
# Top-level functions that can only be used by Kotlin.
-dontwarn retrofit2.KotlinExtensions
-dontwarn retrofit2.KotlinExtensions$*
# With R8 full mode, it sees no subtypes of Retrofit interfaces since they arecreated withaProxy
# and replaces all potential values with null. Explicitly keeping the interfacesprevents this.
-if interface * { @retrofit2.http.* <methods>; }
-keep,allowobfuscation interface <1>-keep class retrofit2.** { *; }
-keep public class theflyy.com.flyy.** {*;}

Additional Methods

Send Events

Values can either be sent in the form of key and value or as a json object.

//To send event related data in string format
 cordova.plugins.FlyyPlugin.trackEvent("<key>", "<value>", function (data) {
        console.log("Track Event Success : " + data)
    }, function(data) {
        console.log("Track Event Error : " + data)
    });

//To send event related data in json format
  cordova.plugins.FlyyPlugin.trackEventJson("<key>", "<value>", function (data) {
        console.log("Track Event Success : " + data)
    }, function(data) {
        console.log("Track Event Error : " + data)
    });

To open deep links

cordova.plugins.FlyyPlugin.openDeeplink(<action in string format>, function (data) {
        console.log("Track Event Success : " + data)
    }, function(data) {
        console.log("Track Event Error : " + data)
    });

To Set Reward Grid Span Count

cordova.plugins.FlyyPlugin.setRewardGridSpanCount("3", function (data) {
        console.log("Rewards grid count Success : " + data)
    }, function(data) {
        console.log("Rewards grid count Error : " + data)
    });

To get share data

cordova.plugins.FlyyPlugin.getShareData("<offer_id>", function (data) {
        console.log("getShareData Success : " + data)
    }, function(data) {
        console.log("getShareData Error : " + data)
    });

To get referral count

cordova.plugins.FlyyPlugin.getReferralCount(function (data) {
        console.log("getReferralCount Success : " + data)
    }, function(data) {
        console.log("getReferralCount Error : " + data)
    });

To get scratch card count

cordova.plugins.FlyyPlugin.getScratchCardCount(function (data) {
        console.log("getScratchCardCount Success : " + data)
    }, function(data) {
        console.log("getScratchCardCount Error : " + data)
    });

To get wallet balance

cordova.plugins.FlyyPlugin.getWalletBalance("<wallet_lable>", function (data) {
        console.log("getWalletBalance Success : " + data)
    }, function(data) {
        console.log("getWalletBalance Error : " + data)
    });

To get referrer details

cordova.plugins.FlyyPlugin.getReferrerDetails(function (data) {
        console.log("getReferrerDetails Success : " + data)
    }, function(data) {
        console.log("getReferrerDetails Error : " + data)
    });

To get offers count

cordova.plugins.FlyyPlugin.getOffersCount(function (data) {
        console.log("getOffersCount Success : " + data)
    }, function(data) {
        console.log("getOffersCount Error : " + data)
    });