Pure SDK - React Native Module
Getting started
yarn add react-native-pure
After installing the module, do the following:
Android
- Open up
android/app/src/main/java/[...]/MainApplication.java
- Add
import com.fluxloop.react.pure.RNPurePackage;
to the imports at the top of the file - Add
new RNPurePackage()
to the list returned by thegetPackages()
method
- Add
- Append the following lines to
android/settings.gradle
:include ':react-native-pure' project(':react-native-pure').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-pure/android')
Insert the following lines inside the allprojects > repositories block in
android/build.gradle
:mavenLocal() mavenCentral() jcenter() maven { url "$rootDir/../node_modules/react-native/android" } maven {url 'https://maven.google.com'} maven { url = "https://dl.bintray.com/fluxloop/pure/"
For more detailed overview on Android dependencies, click here.
Insert the following lines inside the dependencies block in
android/app/build.gradle`
:compile project(':react-native-pure') compile fileTree(dir: "libs", include: ["*.jar"])
IMPORTANT! You also need the following dependencies if not already used by your app in your app build.gradle:
implementation ("com.google.android.gms:play-services-ads-identifier")
implementation ("com.google.android.gms:play-services-location")
IMPORTANT SDK 29 CHANGES:
To request background location on Android 10 when targeting SDK 29, you need to add Manifest.permission.ACCESS_BACKGROUND_LOCATION
as part of your location permission request. android.permission.ACCESS_BACKGROUND_LOCATION
comes bundled with the SDK manifest, but if you're using the SDK without manifest merging, please add this permission manually.
iOS
- In XCode, in the project navigator, right click
Libraries
➜Add Files to [your project's name]
. - Go to
node_modules
➜react-native-pure
➜ios
and addRNPure.xcodeproj
. - In XCode, in the project navigator, select your project.
- Add
libRNPure.a
to your project'sBuild Phases
➜Link Binary With Libraries
. - Under
Build Settings
➜Search Paths
, add$(SRCROOT)/../node_modules/react-native-pure/ios
as non-recursive toHeader Search Paths
andFramework Search Paths
. In the
ios
folder, create a file namedPodfile
with the following content, or merge into your existingPodfile
:target 'yourAppName' do platform :ios, '9.0' #minimum target for pure use_frameworks! pod 'PureSDK', :podspec => 'https://puresdk.azurewebsites.net/cocoapods/versions/1.0.95?key=<PWD>' pod 'RNPure', :path => '../node_modules/react-native-pure/ios' pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga' # Include this for RN <= 0.46 pod 'React', path => '../node_modules/react-native' # Include this for RN >= 0.47 pod 'React', :path => '../node_modules/react-native', :subspecs => [ 'Core', 'CxxBridge' ] pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec' pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec' pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec' end
PWD will be provided by fluxLoop.
Include
pod 'PureSDKBluetooth', :podspec => 'https://puresdk.azurewebsites.net/cocoapods/bluetooth/versions/1.0.95?key=<PASSWORD>
to collect Eddystone UID and Eddystone URL.
Run
pod install
in theios
folder from a terminal window. From now on, use the xcworkspace generated by cocoapods to work on the native iOS files.- Open the
xcworkspace
file that was generated by CocoaPods, located in theios
folder. - In
AppDelegate.m
, add the following with the other imports:#import <PureSDK/Pure.h>
Note: If 'React/RCTBundleURLProvider.h' or 'PureSDK/Pure.h can not be found, add it to your product schemes by doing the following: Navigate toProduct
➜Schemes
➜Manage Schemes
. Select+
and addRNPure
andReact
as shared target. - In
AppDelegate.m
find the method with the launchOptions, and add the following:[Pure initializeWithLaunchOptions:launchOptions];
- Click here for additional settings required (Permissions).
startTracking
must be called to finish initializing the iOS SDK. This can either be done in AppDelegate.m with[Pure startTracking]
after the init call, or be done with the aformentioned javascript function.Usage
`
javascript
import { Pure, PureResult } from 'react-native-pure'; Pure.startTrackingWithResponse((res) => { if (res === PureResult.PURE_ENABLED) { // do something } });
## Available methods
- [Pure SDK - React Native Module](#pure-sdk---react-native-module)
- [Getting started](#getting-started)
- [Android](#android)
- [iOS](#ios)
- [Usage](#usage)
- [Available methods](#available-methods)
- [init()](#init)
- [startTracking()](#starttracking)
- [startTrackingWithResponse()](#starttrackingwithresponse)
- [stopTracking()](#stoptracking)
- [stopTrackingWithResponse()](#stoptrackingwithresponse)
- [isTracking()](#istracking)
- [getClientId()](#getclientid)
- [associateMetadata(string, json)](#associatemetadatastring-json)
- [associateMetadataWithForce(string, json, boolean)](#associatemetadatawithforcestring-json-boolean)
- [createEvent(string, json)](#createeventstring-json)
- [createEventWithForce(string, json, boolean)](#createeventwithforcestring-json-boolean)
<a name="init"></a>
### init()
*Android only - Promise returns undefined for iOS*
The SDK is initialized automatically by default. If you need to override this behaviour, you can do this by adding the following metadata to your AndroidManifest:
```xml
<meta-data android:name="com.pure.sdk.AutoInit" android:value="false" />
To then do your manual init of the SDK:
Pure.init().then((res) => {
// do stuff based on response
});
startTracking()
Starts tracking of the users movement. The SDK stores the previous state, so you don't have to call Pure.startTracking() every time the app launches.
Pure.startTracking();
startTrackingWithResponse()
Starts tracking of the users movement. The SDK stores the previous state, so you don't have to call Pure.startTrackingWithResponse() every time the app launches.
Pure.startTrackingWithResponse().then((res) => {
if (res === PureResult.PURE_ENABLED) {
// do stuff based on response
}
});
stopTracking()
Stops tracking of the users movement.
Pure.stopTracking();
stopTrackingWithResponse()
Stops tracking of the users movement.
Pure.stopTracking().then((res) => {
if (res === PureResult.PURE_DISABLED) {
// do stuff based on response
}
});
isTracking()
Returns true if user is being tracked, false if not.
Pure.isTracking().then((isTracked) => {
// do stuff based on response
});
getClientId()
Returns the client ID.
Pure.getClientId().then((id) => {
// do stuff based on response
});;
associateMetadata(string, json)
Used to add metadata. The type has to be unique for each model you want to preserve. If sending userinfo, it could look something like this:
const userInfo = {userId: 1234567, gender: 'male', 'birthYear': 1980};
Pure.associateMetadata('UserInfo', userInfo).then((res) => {
// do stuff based on if response was success
});
ß
associateMetadataWithForce(string, json, boolean)
Used to add metadata by force. Boolean in argument should be true for force, false for not.
const userInfo = {userId: 1234567, gender: 'male', 'birthYear': 1980};
Pure.associateMetadataWithForce('UserInfo', userInfo, true).then((res) => {
// do stuff based on if response was success
});
createEvent(string, json)
Used to add an event. The name describes what kind of event this is. If sending order information, it could look something like this:
const orderData = {userId: 1234567, orderId: 10001, 'timestamp': '2018-02-01T11:49:31+00:00'};
Pure.createEvent('Order', orderData).then((res) => {
// do stuff based on if response was success
});
createEventWithForce(string, json, boolean)
Used to add an event by force. The name describes what kind of event this is. If sending order information, it could look something like this:
const orderData = {userId: 1234567, orderId: 10001, 'timestamp': '2018-02-01T11:49:31+00:00'};
Pure.createEventWithForce('Order', orderData, true).then((res) => {
// do stuff based on if response was success
});