React Native Quickstart
Estimated time: 20 minutes
This guide will go over:
Conditions and minimum requirements
react-native-appsmiles-apm on npm : https://www.npmjs.com/package/react-native-appsmiles-apm
Conditions and minimum requirements
Minimum Android version: 4.1 (API 16)
Minimum iOS version : 10.0
Minimum XCode version : 10
I. Installation
npm
Download the npm module:
Copy npm install react-native-appsmiles-apm --save
II. Configuration
iOS Android
Add Podfile
in folder ios
Add theses code in Podfile
Copy platform :ios, '10.0'
use_frameworks!
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
source 'https://gitlab.appsmiles.eu/appsmiles/APMSpecs.git'
source 'https://github.com/CocoaPods/Specs.git'
target 'example' do
# Pods for example
# Others pods...
pod 'RCTAPM', :path => '../node_modules/react-native-appsmiles-apm/ios'
use_native_modules!
end
Launch the command line pod install
Insert the following lines inside the dependencies block in android/app/build.gradle
:
Copy implementation project(':react-native-appsmiles-apm')
In global android/build.gradle
Copy //You can set login and password in env variables
def mavenAppsmilesUsername = System.getenv("APPSMILES_ARTIFACTORY_LOGIN") ?: ''
def mavenAppsmilesPassword = System.getenv("APPSMILES_ARTIFACTORY_PASSWORD") ?: ''
//Or in local.properties
def folder = new File( 'local.properties' )
if( folder.exists() ) {
properties.load(project.rootProject.file('local.properties').newDataInputStream())
mavenAppsmilesUsername = properties.getProperty("maven_appsmiles.username") ?: mavenAppsmilesUsername
mavenAppsmilesPassword = properties.getProperty("maven_appsmiles.password") ?: mavenAppsmilesPassword
}
allprojects {
repositories {
//...
maven {
url 'https://artifactory.appsmiles.eu/artifactory/list/appsmiles/'
credentials {
username = mavenAppsmilesUsername
password = mavenAppsmilesPassword
}
}
}
}
If you use a file local.properties
, add maven_appsmiles.username
and maven_appsmiles.password
in file android/local.properties
with your credentials
Copy maven_appsmiles.username=USERNAME
maven_appsmiles.password=PASSWORD
Init the SDK APM.sharedInstance(this); //Init in MainApplication.java and main thread
in the method onCreate()
III. Initialization
Initialize the SDK in App.js
with the keys we provided to you (partnerID, partnerSecret, baseUrl ), your app's package name (appId ).
Copy import { APMModule } from 'react-native-appsmiles-apm' ;
//...
function initSDKAPM () {
APMModule .initAppWithAppID ( '<PARTNER_ID>' , '<PARTNER_SECRET>' , '<APP_ID>' );
APMModule .setDebugMode ( true );
APMModule .setBaseUrl ( '<BASE_URL>' );
}
//...
initSDKAPM ();
https://api-prod1.appsmiles.eu/
https://api-sb.appsmiles.eu/
We host projects on multiple servers, double check with us or your team to verify the base URL
IV. Attaching
Using inheritance
Create a global class AbstractScreen (or edit an existing abstract class) that override the methods :
Copy // @flow
import React , { Component } from 'react' ;
import { APMModule } from 'react-native-appsmiles-apm' ;
export default class AbstractScreen extends Component <*> {
componentDidMount () {
APMModule .componentDidMountWithScreen ( getDisplayName (WrappedComponent));
}
componentDidUpdate () {
APMModule .componentDidUpdateWithScreen ( getDisplayName (WrappedComponent));
}
componentWillUnmount () {
APMModule .componentWillUnmountWithScreen ( getDisplayName (WrappedComponent));
}
function getDisplayName (WrappedComponent) {
return WrappedComponent .displayName || WrappedComponent .name || 'Component' ;
}
}
Have all the screens in your application extend AbstractScreen:
Copy class HomeScreen extends AbstractScreen {
//...
}
class ChatScreen extends AbstractScreen {
//...
}
//etc.
Using Higher Order Components
Also, you can use a HOC (https://reactjs.org/docs/higher-order-components.html )
Copy //@flow
import * as React from "react" ;
import { APMModule } from "react-native-appsmiles-apm" ;
// see https://reactjs.org/docs/higher-order-components.html
export default function withAPM (WrappedComponent : React . ComponentType < any >) {
// ...and returns another component...
return class extends React . Component <{} , {}> {
componentDidMount () {
APMModule .componentDidMountWithScreen ( getDisplayName (WrappedComponent));
}
componentDidUpdate () {
APMModule .componentDidUpdateWithScreen ( getDisplayName (WrappedComponent));
}
componentWillUnmount () {
APMModule .componentWillUnmountWithScreen ( getDisplayName (WrappedComponent));
}
render () {
// ... and renders the wrapped component with the fresh data!
// Notice that we pass through any additional props
return < WrappedComponent { ... this .props} />;
}
};
function getDisplayName (WrappedComponent) {
return WrappedComponent .displayName || WrappedComponent .name || 'Component' ;
}
}
You're done with the installation !
You should be able to see our SDK on your application.
Head to the next section to start integrating our SDK into your app's features .