Initial SDK Setup

360dialog provides a Cordova plugin that offers you the possibility to use the 360dialog SDK from a Cordova mobile application. In this guide, we suppose that you already have a working Cordova app. If it is not the case, please follow the Get Started First

Step 1: Install the plugin

Use the Cordova command to add the plugin to your project.

$ cordova plugin add https://github.com/360dialog/sdk-cordova.git#master

You can alternatively clone our repository using SSH add the plugin locally

git clone git@github.com:360dialog/sdk-cordova.git
cordova plugin add sdk-cordova

Step 2: Modify your config.xml file

In your config.xml file, include the 360dialog SDK preferences:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.d360.cordova.SampleApp" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">

    <platform name="android">
        <!-- The Android init options from the dashboard -->
        <preference name="com.threesixtydialog.app_id" value="<YOUR APP ID>"/>
        <preference name="com.threesixtydialog.api_key" value="<YOUR IOS API KEY>"/>
    </platform>

    <platform name="ios">
        <!-- The iOS init options from the dashboard -->
        <preference name="com.threesixtydialog.app_id" value="<YOUR APP ID>"/>
        <preference name="com.threesixtydialog.api_key" value="<YOUR ANDROID API KEY>"/>
    </platform>

</widget>

Note

The App ID and the API key are required to initialize the SDK. The other preferences are optional.

Each platform has its set of preferences and set-up steps. Refer to the Android or iOS pages for more set up options.

Step 3: Android - Add the google-services.json

Copy your google-services.json file to the root of your Cordova project as explained in Android Push Notification section.

Step 4: Compile and run

At this point you can already compile and run the application.

cordova build android
cordova build ios

The 360dialog SDK will be able to register, receive a device id, send events and receive push paylaods. In the logs (logcat or iOS Console) you should see an output similar to this:

    Starting Cordova SDK 1.x.x
Starting the 360dialog SDK v3.x.x

##################################### SDK device id #################################################
   iyRPX67gMRL4jcbsBhhs4p00000000000000000000000000000000000000000000000000000000000000000000000
#####################################################################################################


##################################### SDK push token #################################################
   8c23510ba6c55ef1d1a3d57e5e5c6e720694ae9a97110000000000000000000000000000000000000000000000000
######################################################################################################

Step 5: Usage

For more examples, please refer to the Cordova Plugin reference.

Please note that not all native SDK capabilities are exposed to Cordova, and only the methods documented above are available.