# How to access a native cordova plugin?

**URL:** <https://forum.ionicframework.com/t/how-to-access-a-native-cordova-plugin/130091>\
**Category:** ionic-v3\
**Created:** [May 9, 2018, 10:43am UTC](https://forum.ionicframework.com/t/how-to-access-a-native-cordova-plugin/130091 "2018-05-09T10:43:12Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dovel](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/dovel/32/127722_2.png) [@Dovel](https://forum.ionicframework.com/u/Dovel)\
**Post date:** [May 9, 2018, 10:43am UTC](https://forum.ionicframework.com/t/how-to-access-a-native-cordova-plugin/130091/1 "2018-05-09T10:43:12Z")

</div>

How to access a native cordova plugin? My case:

I added a method to a plugin in the `plugins` folder. I already tested it on native cordova project. It works great. But the ionic has a wrapper for this plugin. Now I just want to bypass the ionic wrapper and access the cordova js API to call a method.

Ok, to ignore the typescript errors you can just declare an any variable like `let myPlugin: any = ionicPlugin;` and you be able to call whatever you want. It’s an ugly way, necessary for special reasons.

Or how to extend the ionic wrapper?

---

<div class="post-metadata">

**Author:** ![reedrichards](https://avatars.discourse-cdn.com/v4/letter/r/34f0e0/32.png) [@reedrichards](https://forum.ionicframework.com/u/reedrichards)\
**Post date:** [May 9, 2018, 11:02am UTC](https://forum.ionicframework.com/t/how-to-access-a-native-cordova-plugin/130091/2 "2018-05-09T11:02:33Z")

</div>

Depends of the plugin but you could write your own definition’s file

For example, I access the calendar without `ionic-native`. I have a `cordova.d.ts` file I wrote in my project where I’ve got

```
 interface Window {
    plugins: WindowPlugins;
}

interface WindowPlugins {
   calendar: ICalendarService;
}

interface ICalendarService {
    createEvent(title: string, eventLocation: string, notes: string, startDate: Date, endDate: Date, success: any, error: any);
}

```

which could then be use in my app code like

```
window.plugins.calendar.createEvent(...

```

but if the ionic-native wrapper exists, I would rather use it. More users support/helps to maintain these

---

<div class="post-metadata">

**Author:** ![Dovel](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/dovel/32/127722_2.png) [@Dovel](https://forum.ionicframework.com/u/Dovel)\
**Post date:** [May 9, 2018, 11:13am UTC](https://forum.ionicframework.com/t/how-to-access-a-native-cordova-plugin/130091/3 "2018-05-09T11:13:07Z")

</div>

Thanks for fast response.  
I’m using the [Ionic BLE Plugin](https://github.com/don/cordova-plugin-ble-central).

I tried to call

```auto
console.log(Object.keys((<any>window).plugins));

```

result: Some plugin names but not `ble`.

Now I found out, that the `ble` variable es accessible in global scope (window).

```auto
console.log(Object.keys((<any>window).ble));

```

result: All original methods, but not my custom added. In a native cordova project it worked. Maybe the ionic has to re-build it. But how? The changes are not yet built on installed app. (using `ionic cordova run android -lc`)  
I’ll test to reinstall the android platform.

---

<div class="post-metadata">

**Author:** ![Dovel](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/dovel/32/127722_2.png) [@Dovel](https://forum.ionicframework.com/u/Dovel)\
**Post date:** [May 9, 2018, 11:21am UTC](https://forum.ionicframework.com/t/how-to-access-a-native-cordova-plugin/130091/4 "2018-05-09T11:21:05Z")

</div>

Ok, it worked. On ionic you have to reinstall the platform. (or maybe there is another solution?)  
Now you can access the plugin e.g. by:

```auto
(<any>window).ble.yourMethod();

```

This is a quick’n’dirty solution. Of course typed-files are useful.

---

<div class="post-metadata">

**Author:** ![reedrichards](https://avatars.discourse-cdn.com/v4/letter/r/34f0e0/32.png) [@reedrichards](https://forum.ionicframework.com/u/reedrichards)\
**Post date:** [May 9, 2018, 11:56am UTC](https://forum.ionicframework.com/t/how-to-access-a-native-cordova-plugin/130091/5 "2018-05-09T11:56:17Z")

</div>

There is a wrapper actually, you could follow the doc [https://ionicframework.com/docs/native/ble/](https://ionicframework.com/docs/native/ble/)

---

<div class="post-metadata">

**Author:** ![Dovel](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/dovel/32/127722_2.png) [@Dovel](https://forum.ionicframework.com/u/Dovel)\
**Post date:** [May 9, 2018, 1:12pm UTC](https://forum.ionicframework.com/t/how-to-access-a-native-cordova-plugin/130091/6 "2018-05-09T13:12:18Z")

</div>

Right, I already using it. But the wrapper is not actual up to date. Because I’ve just updated the cordova plugin. To test the new method, I easiely bypass the ionic wrapper. In up coming releases (if my pull-request gonna be merged), the ionic wrapper should be updated too.  
In this case I just updated the source files in the ionic project /plugins/ble/ folder (www for the JS API and src/android test it.

Otherwise I have to wait until the the ionic wrapper is updated. Or I have to fork it, publish to npm and update my packages. A long way. Actually I have no idea how the workflow is until ionic updated the wrapper to the latest plugin version.

---

<div class="post-metadata">

**Author:** ![reedrichards](https://avatars.discourse-cdn.com/v4/letter/r/34f0e0/32.png) [@reedrichards](https://forum.ionicframework.com/u/reedrichards)\
**Post date:** [May 9, 2018, 1:44pm UTC](https://forum.ionicframework.com/t/how-to-access-a-native-cordova-plugin/130091/7 "2018-05-09T13:44:48Z")

</div>

Simply awesome 👍

---

<div class="post-metadata">

**Author:** ![mhartington](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mhartington/32/137757_2.png) [@mhartington](https://forum.ionicframework.com/u/mhartington)\
**Post date:** [July 19, 2021, 9:36pm UTC](https://forum.ionicframework.com/t/how-to-access-a-native-cordova-plugin/130091/8 "2021-07-19T21:36:50Z")

</div>

Closed on July 19, 2021, 9:36pm UTC


