• HOME
  • INTEGRATIONS
  • SDKS
  • GUIDES
  • API DOCS
No results for ""
EXPAND ALL

EDIT ON GITHUB

React Native SDK reference

Read time: 2 minutes
Last edited: Jul 28, 2021
SDK version compatibility

The latest version of the SDK is compatible with Xcode 12 and React Native 0.64. If you need support for earlier versions of React Native, refer to older versions of the SDK.

This reference guide documents all of the methods available in the React Native SDK, and explains in detail how these methods work. If you want to dig even deeper, our SDKs are open source. To learn more, read React Native SDK GitHub repository. The online API docs contain the programmatic definitions of every type and method. Additionally you can clone and run a sample application using this SDK.

To learn more about the specific configuration options that are available in this SDK, read the SDK's API docs.

Getting Started

Expo usage

The LaunchDarkly React Native Client SDK does not work with Expo because the SDK uses native modules. Consider using ExpoKit.

Building on top of our Getting Started guide, the following steps will get you started with using the LaunchDarkly SDK in your React Native code.

The first step is to install the LaunchDarkly SDK as a dependency. Add the LaunchDarkly npm dependency to your project and link it to your React Native project.

To add the LaunchDarkly npm dependency:

1npm install --save launchdarkly-react-native-client-sdk
2cd ios/
3pod install

You must have a Podfile in your ios/ directory. After you write the Podfile, run pod install in the ios/ directory. This SDK requires Xcode 12 and compiles against Swift 5.

use_frameworks! and undefined symbols errors

As of v2.1.0 use_frameworks! is not necessary in the Podfile. If you encounter an undefined symbols error when building without use_frameworks! in your Podfile you will need to create a new empty Swift file and accept the prompt to create a matching Objective-C bridging header. If you are building for multiple platforms, add those as targets for the bridging header. If you're still having trouble resolving the undefined symbols error, clean and rebuild and try again.

Here is an example:

1platform :ios, '10.0'
2require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
3
4target 'YOUR_MODULE_NAME' do
5 # Pods for ReactNativeRestwrapper
6 pod 'FBLazyVector', :path => "../node_modules/react-native/Libraries/FBLazyVector"
7 pod 'FBReactNativeSpec', :path => "../node_modules/react-native/Libraries/FBReactNativeSpec"
8 pod 'RCTRequired', :path => "../node_modules/react-native/Libraries/RCTRequired"
9 pod 'RCTTypeSafety', :path => "../node_modules/react-native/Libraries/TypeSafety"
10 pod 'React', :path => '../node_modules/react-native'
11 pod 'React-Core', :path => '../node_modules/react-native'
12 pod 'React-CoreModules', :path => '../node_modules/react-native/React/CoreModules'
13 pod 'React-Core/DevSupport', :path => '../node_modules/react-native'
14 pod 'React-RCTActionSheet', :path => '../node_modules/react-native/Libraries/ActionSheetIOS'
15 pod 'React-RCTAnimation', :path => '../node_modules/react-native/Libraries/NativeAnimation'
16 pod 'React-RCTBlob', :path => '../node_modules/react-native/Libraries/Blob'
17 pod 'React-RCTImage', :path => '../node_modules/react-native/Libraries/Image'
18 pod 'React-RCTLinking', :path => '../node_modules/react-native/Libraries/LinkingIOS'
19 pod 'React-RCTNetwork', :path => '../node_modules/react-native/Libraries/Network'
20 pod 'React-RCTSettings', :path => '../node_modules/react-native/Libraries/Settings'
21 pod 'React-RCTText', :path => '../node_modules/react-native/Libraries/Text'
22 pod 'React-RCTVibration', :path => '../node_modules/react-native/Libraries/Vibration'
23 pod 'React-Core/RCTWebSocket', :path => '../node_modules/react-native'
24
25 pod 'React-cxxreact', :path => '../node_modules/react-native/ReactCommon/cxxreact'
26 pod 'React-jsi', :path => '../node_modules/react-native/ReactCommon/jsi'
27 pod 'React-jsiexecutor', :path => '../node_modules/react-native/ReactCommon/jsiexecutor'
28 pod 'React-jsinspector', :path => '../node_modules/react-native/ReactCommon/jsinspector'
29 pod 'React-callinvoker', :path => "../node_modules/react-native/ReactCommon/callinvoker"
30 pod 'ReactCommon/turbomodule/core', :path => "../node_modules/react-native/ReactCommon"
31 pod 'Yoga', :path => '../node_modules/react-native/ReactCommon/yoga'
32
33 pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
34 pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
35 pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'
36
37 #launchdarkly-react-native-client-sdk dependencies
38 pod 'LaunchDarkly', '5.4.1'
39
40 use_native_modules!
41end

Once the SDK is downloaded and saved in package.json and the other install steps are complete, you'll need to import it into your project:

1import LDClient from 'launchdarkly-react-native-client-sdk';

Once the SDK is installed and imported, you'll want to create a single, shared instance of LDClient, passing in the client and user configuration objects. To create a client instance, you need your environment's mobile key (available on your account settings page). Mobile keys are not secret. You can expose them in your client-side code with no risk.

To create a shared insteance of LDClient:

1let client = new LDClient();
2let config = { "mobileKey": "YOUR_MOBILE_KEY" };
3let user = { "key": "user_key" };
4
5await client.configure(config, user);
Mobile keys

Be sure to use a mobile key from your Environments page. Never embed a server-side SDK key into a mobile application.

Background fetch

The React Native SDK defaults to the background fetch behavior for the platform it's running on.

Lastly, shut down the client when your application terminates. To learn more, read Shutting down.

Data collection

To learn more about data collection within this SDK and implications on submissions to the Apple App Store, read Apple App Store data collection policy.

Supported features

This SDK supports the following features: