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
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.
A Mobile Foundation instance on IBM Cloud OR an on-premise installation of the IBM Mobile Foundation server.
Create React Native Project
- The first step is to create a React Native project. Let's call our app as the MFLiveUpdateApp. Use the React Native CLI to create a new project.
react-native init MFLiveUpdateApp
- Next, add the react native plugin to your app
cd MFLiveUpdateApp
npm install react-native-ibm-mobilefirst-liveupdate —-save
Note : LiveUpdate package supports React Native v0.62.x and above.
- Install Mobilefirst specific cocopods dependencies to the project.
cd ios && pod install
Configure the Application
Android
Make the following changes to AndroidManifest.xml
(
- Add
xmlns:tools="http://schemas.android.com/tools"
to the manifest tag. E.g.
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.mobilefirstapp">
- Add
tools:replace="android:allowBackup"
to the application tag. E.g.
<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
- Install Mobilefirst specific cocopods dependencies to the project.
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
- Android
- iOS
Configuration In MobileFirst Operation Console
- 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
- 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