Integration for Cordova plugin


Follow the steps below

Download the cordova ios plugin from download link and extract the zip file on your pc/mac and you’ll get the extracted plugin folder named as notifyvisitors_cordova.

Download Cardova Plugin

1. Add Plugin (Initialise plugin)

Now put plugin (i.e. notifyvisitors_cordova folder) and your your app in a same folder and add the plugin in your cordova app. To add plugin in your app open command line interface (CLI) i.e. cmd for windows and terminal for mac users and run the following commands.Follow the steps below.

Select All

    cd ~/path_to_your_cordova_app  
    cordova platform add ios
    Cordova plugin add <path/to/plugin>   --variable URL_SCHEME=yourapp   --variable BRAND_ID=YOUR_BRAND_ID   --variable SECRET_KEY=YOUR_SECRET_KEY
    Example:
    cd ~/Desktop/my_cordova_app  
    cordova platform add ios
    cordova plugin add ../notifyvisitors_cordova   --variable URL_SCHEME=myapp   --variable BRAND_ID=52X --variable SECRET_KEY=768B370B0002A3DEE5E8CD991DA80A12 
    //  If you add plugin correctly you will see the following in your CLI.
    ***************************************************************
    * Notifyvisitors iOS Cordova plugin successfully installed *
    ***************************************************************

    

Open your ios Platform App in XCode and go to your project target > capability tab and turn on Push Notifications.

ios-1

2.Showing In-App Notifications

Use following function to show in app popups. Pass the User Token & CustomRule as NSMutableDictionary or pass nil.

Select All

    var arg = [UserTokenArray   , CustomRuleArray ];
    notifyvisitors_cordova.Show(arg);
    

Example:

Select All

    notifyvisitors_cordova.Show();    
    

OR

Select All

    var arg = [{"name":"Jhon"},{"Page":"index.html"}];
    notifyvisitors_cordova.Show(arg);
 
    

If you need to dismiss all inApp notifications currently viewing on screen, you can call DismissAllNotifyvisitorsInAppNotifications method like this:-

Select All

    notifyvisitors_cordova.DismissAllNotifyvisitorsInAppNotifications();
    

3. User Identifiers

To identify the different app users, call the method userIdentifier as follows.

Select All

    var arg = [“User_ID_String”,jsonDataAttributes  ];
    notifyvisitors_cordova.UserIdentifier(arg);

    

4. Showing Notification Center

You can show list of push notification received push notifications in an In-app Notification Center. To launch In-app notification center you can call the following method.

Select All

    notifyvisitors_cordova.NotifyVisitorsNotificationCentre();
    

5. Showing Instant Push Notification

To show instant push notification in your app, you can call the schedulePushNotificationwithNotificationID method like this:-

Select All

    var arg = [“NotificationID”,”tag”,”time_in_second”,”Title”,”message”,”url_to_load”,”icon_image_url”  ];
    notifyvisitors_cordova.schedulePushNotificationwithNotificationID(arg);

    

6. Tracking events

To track the various app events, call the method event like:-

Select All

    var arg = [“eventName”,AttributesDictionary,”Ltv”,”scope”  ];
    notifyvisitors_cordova.trackEvents(arg);

    

Where:

Select All

    // eventName is the name of the event you want to track for example “sale”,
    // AttributesDictionary is the json (Key Value Pair) containing different properties of the event in the form of json object like:-


    var AttributesDictionary = {“price”:”2000”, “Category”:”fancy” };

    // Ltv is the value you want to give to user corresponding to every particular event.  
    // scope - 1 (called every time the function is called)
    //              2 (called once for the session)
    //              3 (called once per lifetime)

    

7. Handle Call to Action Manually

Call the following method in OnDeviceReday Method to set the observer for navigation Views and pages of your App from NotifyVisitors in-App Messages Call to Action Buttons.

Select All

    notifyvisitors_cordova.NSNotificationObserverforViewController();
    

When you set call to action target Navigate In App then the observer triggers a javascript function app.nv_LoadView(); define a function nv_LoadView in your index.js to get the response and handle the button click actions.

Select All

    nv_LoadView:function(arg) {
    var ViewName = arg.ViewControllerToLoad;
    var parm = arg.Parameters;
    var pramJsonString = JSON.stringify(parm);
    var link = ViewName+'?p='+pramJsonString;
       window.location.href = link;
      }

    

When the page loaded to get the array of parameters call the following function as follows:

Select All

    var getParameters = notifyvisitors_cordova.getUrlParameter('p');
    var jsonData =JSON.parse(res);
    var paramValue = jsonData.Your_Param_Key;  ;
    alert(getParameters);
    alert(paramValue);

    


8. Handle Deeplink Navigation

To navigation a link inside app from deeplink url create a nv_HandleOpenUrl.js javascript file in js folder of your app and add in your index.html file before the cordova.js script tag and add the following code inside file:-

Select All

    function handleOpenURL(schemeData) { 
    setTimeout(function() {    
    var link = schemeData.split('://');
    var url = link[1];  
    window.location = url;
    }, 0);  
    }