Calling native code SDKs from ionic

#1

I want to build a hybrid application using ionic framework and started to learn it and found it very interesting
My problem is I purchased a third party library that is only available in the native languages (iOS and Android) and it is a core component in my application that I can’t get rid off or rewrite quickly, is a way to consume those native SDKs using ionic?
Your help is highly appreciated

3 Likes
#2

Ionic itself won’t help you out in this case. What you need to look as is developing a plugin to interact with your third party library so you make calls to it’s API in javascript which are then passed over to the native SDK.

http://cordova.apache.org/docs/en/3.6.0/guide_hybrid_plugins_index.md.html#Plugin%20Development%20Guide

It sounds a lot scarier than it actually is. The hard part is writing the native code to achieve what you want and that’s already been done!

1 Like
#3

Thank you, I actually came across this link you sent and said to myself rewriting the library in Javascript sounds easier :smiley:
Thanks for the assurance that it is not that terrible option, I will try it out

#4

You don’t have to rewrite the library in javascript unless the library is pretty small? Just you have to write a wrapper following the Cordova spec so when you call the following sudo code in JavaScript. It’s honestly not that difficult once you get into it.

navigator.plugins.mylib.mymethod([parameters]);

It sends it through to your library and makes the correct call in Obj-C/Java depending on the platform and returns the right information, or fires off whatever the library is intended to do. It’s difficult to help more without details of the library in question.

#5

Yeah I understand your point and I will try it out, I will let you know if I face any problems if you don’t mind.
As for the library it is an indoor positioning SDK that is available in native languages only
Thanks again :smile:

#6

Nice one! I don’t know which SDK you’re using but there’s plugins for the estimote SDK for cordova that might point you in the right direction if you need to write your own.

#7

I’m looking for something that doesn’t rely on any infrastructure, estimote rely on beacons in positioning, I’m going with either IndoorAtlas or Navizon

#8

https://support.navizon.com/faq/are-your-sdks-able-to-be-used-by-phonegap-or-cordova/

Sounds like Navizon has what you want if you get in touch with them!

1 Like
#9

Awesome thank you :smile:

1 Like
#10

I managed to fix the navizon plugin as was created by one of their customers, I added it successfully to my application as per http://www.mat-d.com/site/tutorial-creating-a-cordova-phonegap-plugin-for-android-app/ but I’m still facing issues when trying to use it

Javascript interface

cordova.define("cordova/plugins/Navizon",
  function (require, exports, module) {
    var exec = require("cordova/exec");
    var Navizon = function () {};
    //-------------------------------------------------------------------
    Navizon.prototype.startLocation = function (successCallback, errorCallback) {
      return exec(successCallback, errorCallback, 'Navizon', 'startLocation', []);
    };
    var navizon = new Navizon();
    module.exports = navizon;
  }
);

Plugin.xml

<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
    xmlns:android="http://schemas.android.com/apk/res/android"
    id="com.android.elis.Navizon"
    version="1.0.0">
    <name>Navizon</name>
    <description>The Navizon Plugin</description>
    <license>Apache 2.0</license>
    <keywords>cordova,navizon</keywords>
    <repo></repo>
    <issue></issue>
    <js-module src="www/navizon.js" name="Navizon">
        <clobbers target="Navizon" />
    </js-module>
    <!-- android -->
    <platform name="android">
        <config-file target="res/xml/config.xml" parent="/*">
            <feature name="Navizon" >
                <param name="android-package" value="com.android.elis.Navizon"/>
				<param name="onload" value="true" />
            </feature>
        </config-file>
        <source-file src="src/Navizon.java" target-dir="src/" />
    </platform>
</plugin>

The problem

I finally was able to build the application, but I don’t know how to refer to the plugin and call startLocation in my application. I tried window.navizon but gave me undefined. can someone please refer me to the missing piece here

#11

Did you manage to get IndoorAtlas working?

#12

I was never trying to I’m afraid. I was just pointing out that there was a cordova plugin already developed to work with the SDK @hamza was looking to use.

#13

We’ve just released an Ionic Starter which also supports IndoorAtlas: http://market.ionic.io/starters/proximiio-ionic-demo-app. Our Cordova Plugin supports also Eddystone Beacons, iBeacons, native location services and some other navigation techs as well.

Free Proximi.io account is required, which you can obtain from the following url: https://portal.proximi.io.

We’re in beta and there’s still some polishing to do especially with the Cordova Plugin and Ionic / Cordova Demo Apps.

#14

Hey @wedgybo, I am going through the same problem now. Like I have third-party native SDKs, which I have to use for building a cross-platform application. Did you manage to build a Cordova Wrapper plugin on top of the SDKs. If so, can you please point me into right direction?

#15

I am trying to use the navizon plugin and getting this error.
error: package com.mexens.android.navizon does not exist

Can you please help me to fix it?

#16

Hi, I am trying to implement same thing. Has anyone done something related to create plugin of native sdk for ionic app ?

#17

It is Feb 2018 and I am trying to do the same thing requested in this thread. I want to integrate a 3rd party Android (aar library) and iOS library as SDK into my ionic App. The 3rd party library is written by another company and developers that we are in agreement with. However, they would deliver only android and iOS libraries only.
Is there an way to integrate libraries using plug-in approach?
OR
Is it possible to make a NPM package of the libraries and then use the NPM package as described in this link “https://ionicframework.com/docs/developer-resources/third-party-libs/”?

Please help with pointers.

#18

@paddy_adsl, I am wondering if you had any success with creating a plugin to access 3rd party SDK native to platform. In other words, plugin in Android version of ionic App to access 3rd party Android SDK and similarly, iOS version of ionic App to access the same 3rd party iOS SDK.
Thanks in advance for the help.

#19

HI wedgybo,
I seen your convesation and excited to ask my doubt.i.e
I have airpush native sdk, in my case how can i use in ionic v3 project.