java_doctor_101
java_doctor_101

Reputation: 3357

Difference between ionic APIs and ionic native API

I am new to ionic and hybrid development in general. Trying to figure out how ionic API translate on the mobile OS.

Let's take following two APIs. Both of the following APIs are provided by ionic2.

This one is an ionic2 API and lets you control the keyboard.

https://ionicframework.com/docs/api/platform/Keyboard/

This one is also ionic2 API but they call it an ionic native API.

https://ionicframework.com/docs/native/keyboard/

My specific questions.

What is the difference between these two? I would appreciate an answer that can describe the end of flow for each of these APIs. By end to end, I mean JS stack, some Cordova bridge, web view and native functions/callback in Java/obj-c

Upvotes: 4

Views: 880

Answers (1)

Andreas Gassmann
Andreas Gassmann

Reputation: 6544

Generally speaking, Ionic APIs are related to the actual "app" running in the web view and Ionic Native APIs are used to talk to your device.

I think the Keyboard API is a special case and I never noticed that there are two "different" APIs. The APIs are not the same, so my advice would be to try and use the API that matches your needs best (if both work, I would use the Ionic API https://ionicframework.com/docs/api/platform/Keyboard/ ).

The way you use native features of your device in hybrid development is by using cordova plugins. Those plugins give you a javascript interface for executing native Java / Objective-C code. Ideally the cordova plugin supports both iOS and Android, which means you don't have to worry about the platform your app is running on when using that feature.

Because Ionic is build with Typescript, they maintain Ionic Native as a way to make it easier to work with cordova plugins. It is just a wrapper around regular cordova plugins with some extra features like promise support and types. You don't have to use Ionic Native when using cordova plugins, but if Ionic Native supports the plugin, I highly recommend using it.

The Ionic APIs here https://ionicframework.com/docs/api/ are APIs to interact with your apps behaviour. You can use it to control navigation, modals, infinite-scroll and so on.

Your "end-to-end flow" depends a lot on the feature you are trying to implement.

As a rule of thumb, I would always look for features in the Ionic API first. The Ionic API usually provides the features most people need. But if you need to talk to native features of your device (you need device data like GPS or access to storage, etc.) you have to find a cordova plugin that does what you need. If you find one, check if there is an Ionic Native wrapper available.

Upvotes: 4

Related Questions