Skip to content

Project consists on a Cordova plugin wrapping Weplan's SDK and an Ionic project demoing its usage

Notifications You must be signed in to change notification settings

weplan-analytics/weplan-sdk-cordova-plugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Weplan SDK Ionic/Cordova Plugin

A cordova plugin to enable/disable Weplan SDK on Android platform.

Usage with Apache/Cordova

Add plugin to cordova project

cordova plugin add https://github.com/weplan-analytics/weplan-sdk-cordova-plugin.git

Use after deviceready event, calling the plugin as follow:

    // Enable SDK
    cordova.exec(
        function(winParam) {},
        function(error) {},
        "WeplanSdk",
        "enableSdk",
        [
            "YOUR_CLIENT_ID",       // Update with your ClientId
            "YOUR_CLIENT_SECRET",   // Update with your ClientSecret
            true                    // This will enable sdk on app updates to those devices with location permission previously granted
        ]
    );

    // Disable SDK
    cordova.exec(
        function(winParam) {},
        function(error) {},
        "WeplanSdk",
        "disableSdk",
        []
    );

Usage with Ionic

Add cordova plugin

npm i https://github.com/weplan-analytics/weplan-sdk-cordova-plugin.git

Wrap cordova plugin creating a new provider/service:

ionic g service weplanSdk

Install Ionic Native

npm install --force @ionic-native/core@5.36.0

Replace the content of the generated file (weplan-sdk.service.ts) with the following plugin wrap:

    // weplan-sdk.service.ts
    
    import { Injectable } from  '@angular/core';
    import { cordova, IonicNativePlugin } from  '@ionic-native/core';
    
    @Injectable()
    export  class  WeplanSdkService  extends  IonicNativePlugin {
	    static override pluginName = 'weplansdk';
	    static override plugin = 'cordova-plugin-weplansdk';
	    static override pluginRef = 'WeplanSdk';
	    static override platforms = ['Android'];
	      
	    enableSdk(clientId: string, clientSecret: string, startOnUpdate: boolean): Promise<any> {
		    return  cordova(this, 'enableSdk', {}, [clientId, clientSecret, startOnUpdate]);
	    }
	    
	    disableSdk(): Promise<any> {
		    return  cordova(this, 'disableSdk', {}, []);
	    }
    }

Include the service on the project as provider in app.module.ts

Now you can use the service anywhere on the project

    import { WeplanSdkService } from  './weplan-sdk.service';
    
    constructor(private weplanSdk: WeplanSdkService) { 
        weplanSdk.enableSdk(
            "YOUR_CLIENT_ID",       // Update with your ClientId
            "YOUR_CLIENT_SECRET",   // Update with your ClientSecret
            true                    // This will enable sdk on app updates to those devices with location permission previously granted
        )
        //weplanSdk.disable()
    }

About

Project consists on a Cordova plugin wrapping Weplan's SDK and an Ionic project demoing its usage

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published