React Native
This page will guide you through the integration of Revlum in your React Native app
React Native library for integrating the Revlum Offerwall SDK. Easily configure and launch an offerwall on Android and iOS, allowing users to earn rewards through engaging offers.
The Revlum Offerwall Plugin is a React Native plugin that wraps the native Revlum Offerwall SDK implementations for both Android and iOS. For more details on the native implementations, you can refer to the official documentation for iOS and Android.
Android | iOS | |
---|---|---|
Support | minSdk 24 | iOS 16.0+ |
Installation
Install the package using yarn
:
yarn add react-native-offerwall
or with npm
:
npm install react-native-offerwall
Setup
Android
Minimum SDK Requirement: Ensure that your Android minSdkVersion
is set to 24 or higher.
Add Revlum Maven Repository: In your Android project, navigate to your android/build.gradle
file and ensure that the Revlum Maven repository is added under the allprojects
section. It should look like this:
allprojects {
repositories {
maven {
url = uri("https://sdk-revlum-android.s3.amazonaws.com/")
content {
includeGroup("com.revlum")
}
}
google()
mavenCentral()
}
}
iOS
Modify AppDelegate.mm
: In your AppDelegate.mm
, set up the navigation controller as shown below:
#import "AppDelegate.h"
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.moduleName = @"OfferwallExample";
self.initialProps = @{};
NSURL *jsCodeLocation = [self bundleURL];
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
moduleName:@"OfferwallExample"
initialProperties:nil
launchOptions:launchOptions];
UIViewController *rootViewController = [UIViewController new];
rootViewController.view = rootView;
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
[self.window makeKeyAndVisible];
return YES;
}
- (NSURL *)bundleURL
{
#if DEBUG
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
#else
return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
}
@end
Usage
1. Configure the Offerwall
Before launching the Offerwall or checking for rewards, configure the SDK by calling the configure
method. You need to provide the API key and optional parameters like userId
and subId
. If you do not provide a user ID, the SDK will automatically generate one. If a user ID is set, it will be used unless manually changed.
import { configure } from 'react-native-offerwall';
const initOfferwall = async () => {
try {
await configure('your_api_key', null, 'Revlum');
} catch (error) {
console.error('Configure error:', error);
}
};
2. Launch the Offerwall
After configuring the SDK, you can launch the Offerwall using the launch
method:
import { launch } from 'react-native-offerwall';
const handleLaunchOfferwall = async () => {
try {
await launch();
} catch (error) {
console.error('Launch error:', error);
}
};
3. Check for rewards
Check for rewards by using the checkReward
function. It returns a reward value (which will be 0 if there is no reward) and a list of conversions:.
import { checkReward } from 'react-native-offerwall';
const checkRewards = async () => {
try {
const rewardData = await checkReward();
console.log('Reward:', rewardData.reward);
} catch (error) {
console.error('Check reward error:', error);
}
};
Full Example
import { useRef, useEffect } from 'react';
import { View, Button, AppState, AppStateStatus, StyleSheet } from 'react-native';
import { configure, launch, checkReward } from 'react-native-offerwall';
export default function App() {
const appState = useRef(AppState.currentState);
useEffect(() => {
const _initOfferwall = async () => {
try {
await configure('your_api_key', null, 'Revlum');
} catch (error) {
console.error('Configure error:', error);
}
};
_initOfferwall();
const _checkRewards = async () => {
try {
const rewardData = await checkReward();
console.log(`checkReward: reward: ${rewardData.reward}`);
} catch (error) {
console.error('checkReward error:', error);
}
};
const subscription = AppState.addEventListener('change', (nextAppState: AppStateStatus) => {
if (appState.current.match(/inactive|background/) && nextAppState === 'active') {
_checkRewards();
}
appState.current = nextAppState;
});
return () => {
subscription.remove();
};
}, []);
const _handleLaunchOfferwall = async () => {
try {
await launch();
} catch (error) {
console.error('Launch error:', error);
}
};
return (
<View style={styles.container}>
<Button title="Launch Offerwall" onPress={_handleLaunchOfferwall} />
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
});
Updated 21 days ago