Cordova callback inside service layer

Hey all, I’m hoping someone can help me wrap my brain around a concept… I’m trying to incorporate a cordova plugin into a service, but I’m not sure how to implement that.

cordova.exec requires callback methods. I’ve considered promises or observables to try to act as a go between the service method and the callback but I can’t quite understand how I might do that.

Am I over thinking this? Has anyone else done this?

Yes. It’s the entire basis of ionic-native.

1 Like

What about for plugins that aren’t wrapped up in ionic-native? I guess I can look at the code on github for it to see how they’re doing it.

Actually, that’s exactly what I need, I think. I can just add the ionic-native plugin, create a new class for my custom plugin in my own codebase, then include it in @NgModule. I think that will work. Thanks rapropos! I’ll test it tonight and try to remember to report back. :wink:

Oh ya, this worked like a charm! Thanks again @rapropos!

1 Like

If you did this for a public Cordova plugin, please share it with us via a Pull Request for Ionic Native!
Any learning that would be worth sharing about building own plugins for Ionic Native?

I’ve had to customize a plugin to my needing, but I intend to publish the fork publicly once I’m done with my customizations and then I can add a pull request for Ionic Native. Thanks for the suggestion!

I did find this great article on how to update your code in the platforms/android/platform_www/plugins/ directory and then copy it out to your actual plugin repository once you’re have what you want, just to speed up development. That was a huge time saver. Can’t seem to find it right now, but that was the gist of it.

1 Like