yarn add react-native-button-sdk
or
npm install --save react-native-button-sdk
- Install the CocoaPod:
cd ios && pod install
- Update
ios/YOUR_PROJECT/AppDelegate.m
:
Add this import to the top:
@import Button;
Setup iOS SDK with your application key in the didFinishLaunchingWithOptions
method:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// ... other Objective-C code
#ifdef DEBUG
// Enable debug logging (optional)
Button.debug.loggingEnabled = YES;
#endif
[Button configureWithApplicationId:@"YOUR iOS APPLICATION ID" completion:nil];
// ... other Objective-C code
return YES;
}
- If you want to open other apps with the Button browser, you may need to add their app schemes to the
LSApplicationQueriesSchemes
key in yourInfo.plist
file. Take a look at the Button iOS integration guide for how to do that.
- Update
android/app/build.gradle
with the Button SDK dependency:
dependencies {
// ...other Gradle dependencies
implementation 'com.usebutton:android-sdk:6.+'
implementation "com.facebook.react:react-native:+"
// ...other Gradle dependencies
}
- Update
android/app/src/main/java/YOUR/APP/IDENTIFIER/MainApplication.java
:
Add Button SDK import at the top:
import com.usebutton.sdk.Button;
Update the onCreate
method:
@Override
public void onCreate() {
super.onCreate();
// ...other Java code
if (BuildConfig.DEBUG) {
// Enable debug logging (optional)
Button.debug().setLoggingEnabled(true);
}
Button.configure(this, "YOUR ANDROID APPLICATION ID");
// ...other Java code
}
- If you have Proguard enabled, please see the Android SDK integration guide for the rules to include.
import ButtonSDK from "react-native-button-sdk";
// Fetch a purchase path from Button and start the browser
ButtonSDK.startPurchasePath({
url: "https://the.button.url",
token: "my-tracking-token",
headerTitle: "My Button Browser Title",
headerSubtitle: "My Button Browser Subtitle",
headerTitleColor: "#FFFFF",
headerSubtitleColor: "#FFFFF",
headerBackgroundColor: "#FFFFF",
headerTintColor: "#FFFFF",
footerBackgroundColor: "#FFFFF",
footerTintColor: "#FFFFF"
});
// Open the browser with a non-Button merchant URL
ButtonSDK.openURL({
url: "https://www.google.com",
title: "My Browser Title",
subtitle: "My Browser Subtitle"
});
// On user login
ButtonSDK.setIdentifier(id);
// On user logout
ButtonSDK.clearAllData();
Take a look at the Button iOS integration guide or Android SDK integration guide for native integration issues and if there is anything missed please submit a PR to update the above instructions!