This is just a POC at the moment.
This package can be installed directly in a React Native project, allowing the JS SDK access native features of Android and iOS. The main idea of this POC is to prove that only one package has to be installed by the user, instead of both js-sdk and the native module.
$ npm install aerogear-react-native-sdk --save
This step is usually enough
$ react-native link aerogear-react-native-sdk
In case automatic installation didn't work
iOS
- In XCode, in the project navigator, right click
Libraries
➜Add Files to [your project's name]
- Go to
node_modules
➜aerogear-react-native-sdk
and addMobileCore.xcodeproj
- In XCode, in the project navigator, select your project. Add
libMobileCore.a
to your project'sBuild Phases
➜Link Binary With Libraries
- Run your project (
Cmd+R
)<
Android
- Open up
android/app/src/main/java/[...]/MainActivity.java
- Add
import com.reactlibrary.MobileCorePackage;
to the imports at the top of the file - Add
new MobileCorePackage()
to the list returned by thegetPackages()
method
- Append the following lines to
android/settings.gradle
:include ':aerogear-react-native-sdk' project(':aerogear-react-native-sdk').projectDir = new File(rootProject.projectDir, '../node_modules/aerogear-react-native-sdk/android')
- Insert the following lines inside the dependencies block in
android/app/build.gradle
:compile project(':aerogear-react-native-sdk')
Import the desired module and instantiate, passing the necessary configuration parameters:
import { RNMetricsService } from "aerogear-react-native-sdk";
import React, { Component } from "react";
class MyComponent extends Component {
componentWillMount() {
const metricsService = new RNMetricsService({
url: "http://your-metrics-service/metrics"
});
metricsService.sendAppAndDeviceMetrics()
.then(() => this.handleSuccess())
.catch(err => this.handleError(err));
}
render() {
...
}
}