Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic 3 : How to use cordova plugins

I'm trying to use this cordova plugin https://github.com/litehelpers/Cordova-sqlcipher-adapter.

Here my code :

...
import { Platform } from 'ionic-angular';

declare var cordova;

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {

  constructor(platform: Platform) {
    platform.ready().then(() => {
      alert(cordova.plugins.sqlitePlugin);
    });
  }

The problem is, what-ever I do, sqlitePlugin is always undefined :/ However cordova.plugins is an object.

I also tried alert((<any>window).plugins.sqlitePlugin); but the result is the same.

I'm running in an Nexus 5X Android 8 device.

I have installed the plugin this way : ionic cordova plugin add cordova-sqlcipher-adapter --save as a standard cordova plugin.

Any helps would be appreciate :)

like image 272
Whyzx Avatar asked Jul 17 '17 20:07

Whyzx


People also ask

How do Cordova plugins work?

A plugin is a package of injected code that allows the Cordova webview within which the app renders to communicate with the native platform on which it runs. Plugins provide access to device and platform functionality that is ordinarily unavailable to web-based apps.


2 Answers

After several hours, the correct way to use the plugin was : (<any>window).sqlitePlugin

Hope it could helps :)

like image 159
Whyzx Avatar answered Sep 23 '22 13:09

Whyzx


It's work for me

window["pluginName"].pluginFunction
like image 41
ShadowUC Avatar answered Sep 20 '22 13:09

ShadowUC