The Connecthings Cordova plugin allows you to initialize the SDK, access to the GDPR methods and In-App actions methods from the js code.

A cordova demo application is available on github to shows you a concrete implementation.

You just have to clone the https://github.com/Connecthings/cordova-app-demo repo

Install the plugin

You need to run the following command:

cordova plugin add https://github.com/Connecthings/cordova-bridge-connecthings.git

To uninstall the plugin:

cordova plugin remove cordova-bridge-connecthings

How to use it

Initialization

First you need to seize your Connectings' identifiers:

  • The Herow platform you use
  • Your username
  • Your password
  • Your company key

To have more information about every parameters again, we invite you to consult our documentation.

Let's see, how to overwrite these identifiers:

  • For Android, you need to create a xml file called "connecthings-settings.xml".
<?xml version="1.0" encoding="utf-8"?>
<resources>
 	<string name="ct_url_type">LOCAL / DEMO / ITG / PRE_PROD / PROD</string>
    <string name="ct_login">your login</string>
    <string name="ct_password">your password</string>
    <string name="ct_company">your comapny</string>
</resources>

And then overwrite, the resource from your config.xml file :

<resource-file src="www/assets/connecthings-settings.xml" target="app/src/main/res/values/connecthings-settings.xml" />
  • For iOS, you need to create a xml file called "connecthings-settings.plist".
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
	<dict>
		<key>ct_url_type</key>
		<string>LOCAL / DEMO / ITG / PRE_PROD / PROD / PROD_US</string>
		<key>ct_login</key>
		<string>your login</string>
		<key>ct_password</key>
		<string>your password</string>
		<key>ct_company</key>
		<string>your comapny</string>
	</dict>
</plist>

Again, you need to override, the resource file from your config.xml file :

<resource-file src="www/assets/connecthings-settings.plist" target="connecthings-settings.plist" />

And that's it, you're good to go.

Managing location permission

To be efficient the Connecthings' SDK need to have access to the location permission. You can of course handle the permission yourself or otherwise you can use the following method :

ConnecthingsBridge.askPermissions("ACCESS_FINE_LOCATION");

Being compliant with GDPR

You have 4 methods available to help you to be GDPR compliant :

  • ConnecthingsBridge.hasOptinsBeenAsked();
  • ConnecthingsBridge.updateOptin(type, value);
  • ConnecthingsBridge.allOptinsAreUpdated();
  • ConnecthingsBridge.isOptinAuthorized(type, function(result));

You can find out more about this by reading our GDPR tutorial.

Please find below a short workflow example:

// Check if the optins have already been asked
ConnecthingsBridge.hasOptinsBeenAsked(function(pluginResult) {
    console.log("hasOptinsBeenAsked: " + pluginResult["hasOptinsBeenAsked"]);
});

//give the optin to the SDK: USER_DATA is mandatory
ConnecthingsBridge.updateOptin("USER_DATA", true);
ConnecthingsBridge.updateOptin("STATUS", true);

// Notify the SDK that all optins has been given - must be called each time you update optin
ConnecthingsBridge.allOptinsAreUpdated();

// Check the status of any optin
ConnecthingsBridge.isOptinAuthorized("USER_DATA", function(pluginResult) {
    optinResult.innerHTML = "";
    optinResult.innerHTML = "USER_DATA: " + pluginResult["isOptinAuthorized"];
});

To learn more about this you can read our dedicated tutorial.

The In-App actions

The following methods allow your application to use the in-app actions.

In-app Actions are actions/messages triggered on a user's phone when the application is active in the foreground.

You can find out more about this by reading our In-App actions tutorial.

To be able to react to in-app action, you need:

  • First, to register your in-app action thanks to the registerInAppAction() method :
ConnecthingsBridge.registerInAppAction();
  • Then, you need to create two functions: createInAppAction & removeInAppAction.
ConnecthingsBridge.alert.createInAppAction = function(pluginResult) {
	var placeInformation = pluginResult["placeInAppAction"];
};

ConnecthingsBridge.alert.removeInAppAction = function(pluginResult) {

};
  • Last, but not least, as soon as you finished to use the in-app system, you need to unregister the listener by using the following method :
ConnecthingsBridge.unregisterInAppAction();

To know everything about in-app action, please consult our documentation.

Android

  • For debugging the native side, you can use Android Studio and open your application perspective on the Android platform result (sample/platforms/android).
  • For debugging the client javascript side, you can use chrome, you can read this tutorial to learn how to do it.

IOS

  • For debugging the native side, you can use XCode, you need to open your application perspective on the ios platform result (sample/platforms/ios).
  • For the client side, you can use safari, just follow this little tutorial.