Home Reference Source

React Native SDK for IBM Mobile Foundation LiveUpdate

Description

The Live Update feature in Mobile Foundation provides a simple way to define and serve different configurations for users of an application. It includes a component in the MobileFirst Operations Console for defining the structure of the configuration as well as the values of the configuration.

LiveUpdate React Native SDK lets you query runtime configuration properties and features which you set in the LiveUpdate Settings screen in the MobileFirst Operations Console. With LiveUpdate integrated in your application you can implement feature toggling, A/B testing, feature segmentation and more..

Read more about Live Update here.

Installation

The IBM MobileFirst™ LiveUpdate SDK for React Native apps is dependent on the IBM MobileFirst Foundation SDK. If you have already added the IBM MobileFirst Foundation SDK to your app, continue with the instructions below.

Navigate to the folder of your React Native app and run the following command to install the LiveUpdate SDK for React Native apps.

npm install react-native-ibm-mobilefirst-liveupdate --save

Getting Started

Pre-requisites

  1. Make sure you have all the pre-requisites for a React Native app covered. See the React Native Getting Started page if you're new to this whole stuff.

  2. A Mobile Foundation instance on IBM Cloud OR an on-premise installation of the IBM Mobile Foundation server.

Create React Native Project

react-native init MFLiveUpdateApp

cd MFLiveUpdateApp

npm install react-native-ibm-mobilefirst-liveupdate —-save

Note : LiveUpdate package supports React Native v0.62.x and above.

cd ios && pod install

Configure the Application

Android

Make the following changes to AndroidManifest.xml (/android/app/src/main/)

<manifest
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  package="com.mobilefirstapp">
<application
      android:name=".MainApplication"
      android:label="@string/app_name"
      android:icon="@mipmap/ic_launcher"
      android:allowBackup="false"
      android:theme="@style/AppTheme"
      tools:replace="android:allowBackup">
iOS

cd ios && pod install

This step is applicable only for iOS platform.

Test the Application

Android

  • To run the application :

react-native run-android

iOS

  • To run the application :

react-native run-ios

Supported platforms

Configuration In MobileFirst Operation Console

  1. Add a scope mapping for liveupdate.mobileclient in MobileFirst Operations Console → [your application] → Security tab → Scope-Elements Mapping. Map it to an empty string if you want to use the default protection or to a security check if you're using one.

Learn more about scope mapping

  1. You can add schemas and features from the MobileFirst Operations Console → [your application] → Live Update Settings

Once you've setup schemas and features you can start use the client side API.

Sample Usages of the API

var useClientCache = false; //True (default)

var featureId = 'featureId';
var propertyId = 'propertyId' ;

MFLiveUpdate.obtainConfiguration(useClientCache)
  .then(result => {

 console.log('Is feature enabled for' + featureId + ':' + result.isFeatureEnabled('featureId'));
console.log ('Property value for the ' + propertyId + 'is :' +result.getProperty('propertyId'));


 })
  .catch(err => console.log('There was an error:' + err))

Documentation

Copyright 2020 IBM Corp.

IBM - IBM MobileFirst Platform Foundation v8.0 license agreement

Terms of Use